Animator
The main class responsible for the playback and replication of Animations. All replication of playing AnimationTracks is handled through the Animator instance.
See also Animation Editor and Using Animations to learn how to create and add pre-built or custom animations to your game.
Summary
Properties
Methods
Computes relative velocities between parts and apply them to Motor6D.Part1. These relative velocity calculations and assignments happen in the order provided.
Returns the list of currently playing AnimationTracks.
Loads an Animation onto an Animator, returning an AnimationTrack.
Increments the AnimationTrack.TimePosition of all playing AnimationTracks that are loaded onto the Animator, applying the offsets to the model associated with the Animator. For use in the command bar or by plugins only.
Events
Fires when the Animator starts playing an AnimationTrack.
Properties
Methods
ApplyJointVelocities
Parameters
Returns
StepAnimations
Parameters
Returns
Code Samples
local RunService = game:GetService("RunService")
local function studioPreviewAnimation(model, animation)
-- find the AnimationController and Animator
local animationController = model:FindFirstChildOfClass("Humanoid")
or model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animationController or 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"
studioPreviewAnimation(character, animation)