学习
引擎类
Animator

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处



API 参考
属性
EvaluationThrottled
只读
未复制
写入并联
功能: Animation
Animator.EvaluationThrottled:boolean

PreferLodEnabled
读取并联
功能: Animation
Animator.PreferLodEnabled:boolean

RootMotion
只读
未复制
不可浏览
写入并联
功能: Animation
Animator.RootMotion:CFrame

RootMotionWeight
只读
未复制
不可浏览
写入并联
功能: Animation
Animator.RootMotionWeight:number

方法
ApplyJointVelocities
功能: Animation
Animator:ApplyJointVelocities(motors:Variant):()
参数
motors:Variant
返回
()

GetPlayingAnimationTracks
功能: Animation
模拟访问权限
Animator:GetPlayingAnimationTracks():{any}
返回

GetTrackByAnimationId
功能: Animation
模拟访问权限
Animator:GetTrackByAnimationId(animationId:ContentId):AnimationTrack?
参数
animationId:ContentId
代码示例
通过 ID 获取动画轨道
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ANIM_ID = "rbxassetid://2515090838"
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- 确保角色的 humanoid 包含一个 Animator 对象
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- 创建一个新的 Animation 实例并分配动画资产 ID
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- 将动画加载到 animator
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- 在短暂延迟后播放动画轨道
task.wait(3)
kickAnimationTrack:Play()
local startTime = tick()
RunService:BindToSimulation(function(deltaTime: number)
if tick() - startTime > 1 then
-- 通过 ID 获取轨道并停止播放
local kickTrack = animator:GetTrackByAnimationId(ANIM_ID)
if kickTrack and kickTrack.IsPlaying then
kickTrack:Stop()
end
end
end)

LoadAnimation
功能: Animation
模拟访问权限
Animator:LoadAnimation(animation:Animation):AnimationTrack
参数
animation:Animation

RegisterEvaluationParallelCallback
功能: Animation
Animator:RegisterEvaluationParallelCallback(callback:function):()
参数
callback:function
返回
()

StepAnimations
插件安全性
功能: Animation
Animator:StepAnimations(deltaTime:number):()
参数
deltaTime:number
返回
()
代码示例
在Studio中预览动画
local RunService = game:GetService("RunService")
local function previewAnimation(model, animation)
-- 查找 AnimationController 和 Animator
local animationController = model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animator then return end
-- 加载动画以创建 AnimationTrack
local track = animationController:LoadAnimation(animation)
track:Play()
-- 预览动画
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- 停止动画
track:Stop(0)
animator:StepAnimations(0)
-- 重置关节
for _, descendant in pairs(model:GetDescendants()) do
if descendant:IsA("Motor6D") then
local joint = descendant
joint.CurrentAngle = 0
joint.Transform = CFrame.new()
end
end
end
local character = script.Parent
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
previewAnimation(character, animation)

活动
AnimationPlayed
功能: Animation
Animator.AnimationPlayed(animationTrack:AnimationTrack):RBXScriptSignal
参数
animationTrack:AnimationTrack

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。