Engine Class
Animator
Summary
Properties
Methods
ApplyJointVelocities(motors: Variant):() |
GetTrackByAnimationId(animationId: ContentId):AnimationTrack? |
LoadAnimation(animation: Animation):AnimationTrack |
RegisterEvaluationParallelCallback(callback: function):() |
StepAnimations(deltaTime: number):() |
Events
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
API Reference
Properties
Methods
ApplyJointVelocities
Animator:ApplyJointVelocities(motors:Variant):()
Parameters
motors:Variant |
Returns
()
GetTrackByAnimationId
Parameters
animationId:ContentId |
Returns
Code Samples
Get Animation Track by 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()
-- Ensure that the character's humanoid contains an Animator object
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Create a new Animation instance and assign an animation asset ID
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- Load the animation onto the animator
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- Play the animation track after a short delay
task.wait(3)
kickAnimationTrack:Play()
local startTime = tick()
RunService:BindToSimulation(function(deltaTime: number)
if tick() - startTime > 1 then
-- Get track by ID and stop its playback
local kickTrack = animator:GetTrackByAnimationId(ANIM_ID)
if kickTrack and kickTrack.IsPlaying then
kickTrack:Stop()
end
end
end)LoadAnimation
Parameters
Returns
RegisterEvaluationParallelCallback
StepAnimations
Parameters
Returns
()
Code Samples
Preview Animation in Studio
local RunService = game:GetService("RunService")
local function previewAnimation(model, animation)
-- Find the AnimationController and Animator
local animationController = model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animator then return end
-- Load the Animation to create an AnimationTrack
local track = animationController:LoadAnimation(animation)
track:Play()
-- Preview the animation
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- Stop the animation
track:Stop(0)
animator:StepAnimations(0)
-- Reset the joints
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)Events
AnimationPlayed
Parameters