Skip to content

Animation ​

A MeshPart plays the animations in its model file, such as a glTF character's walk cycle. There are three levels, and you can mix them:

  1. PlayAnimation: one animation at a time
  2. AnimationTracks: several animations blended by weight and priority
  3. an Animator: a state machine that drives tracks from parameters you set

IKControl then bends chains of bones on top of whatever plays. Models are posed on the CPU and uploaded each frame they change.

Mesh animations ​

luau
local hero = Instance.new("MeshPart")
hero.MeshId = "assets/Hero.glb"
hero.Parent = Scene
hero:PlayAnimation("Walk", true)
MemberDoes
GetAnimations()The model's animation names. Empty until it loads
PlayAnimation(name, looped)Starts from the first key. Before the model loads it waits, and quietly gives up if the name doesn't exist; after, an unknown name errors
StopAnimation()Back to the rest pose
AnimationSpeed1 by default. Negative plays backwards from the end
AnimationLoopedCan change while playing
AnimationTimeSeconds in. Setting it poses the model there
CurrentAnimationThe animation posing the model. Stays set after it ends
IsAnimationPlayingWhether it's still moving
AnimationEnded(name)Fires when a non-looped animation reaches its last key, where it holds

None of this is saved in a place.

Tracks ​

To walk and wave at once, load each animation as a track:

luau
local walk = hero:LoadAnimation("Walk")
walk.Looped = true
walk:Play()

local wave = hero:LoadAnimation("Wave")
wave.Priority = Enum.AnimationPriority.Action
wave:Play(0.2)
  • Play(fadeTime = 0.1, weight = 1, speed = 1) fades in. Stop(fadeTime) fades out.
  • AdjustWeight(weight, fadeTime) and AdjustSpeed(speed) change it while playing.
  • TimePosition, Looped, Length, IsPlaying, WeightCurrent, WeightTarget.
  • Events: Stopped when it stops, Ended once faded out, DidLoop on each wrap.
  • A non-looped track holds its last pose at the end, then fades out.
  • hero:GetPlayingAnimationTracks() lists what's playing.

Blending. Each node is posed by the weighted tracks, highest Priority first: Action4 down to Action, then Movement, Idle, and Core (the default, lowest). Tracks at the same priority share a weight of up to 1 in proportion to their weights; lower priorities get what's left, and the rest pose takes any remainder. An animation started with PlayAnimation sits under every track.

Tracks aren't saved. A part drops a track once it has faded out and nothing holds it.

Markers ​

Line up footsteps and effects with named moments:

luau
walk:AddMarker("Footstep", 0.0, "left")
walk:AddMarker("Footstep", 0.5, "right")
walk:GetMarkerReachedSignal("Footstep"):Connect(function(foot)
	stepSound:Play()
end)

AddMarker(name, time, value?) puts a marker at time seconds. The signal fires with value (empty string by default) every time the track passes it, on every loop and backwards too. A marker at the start fires on the first step. GetMarkers() lists them by time and RemoveMarkers(name?) removes them. Markers in the model file aren't read.

Animator ​

An Animator runs a state machine over the model's animations, like Unity's Animator or Godot's AnimationTree. Your script sets numbers and flags; the animator decides what plays.

luau
local animator = Instance.new("Animator")
animator.Parent = hero
animator:AddBlendState("Move", "Speed", { { "Idle", 0 }, { "Walk", 4 }, { "Run", 12 } })
animator:AddState("Jump", "Jump", false)
animator:AddTransition("Move", "Jump", { { "Jump" } }, 0.1)
animator:AddTransition("Jump", "Move", { { "Grounded", "==", true } }, 0.2, 0.8)

Run.Heartbeat:Connect(function()
	local velocity = controller.Velocity
	animator:SetNumber("Speed", Vector3.new(velocity.X, 0, velocity.Z).Magnitude)
	animator:SetBool("Grounded", controller.OnGround)
end)

local function jump()
	controller:Jump()
	animator:SetTrigger("Jump")
end

States.

  • AddState(name, animation, looped = true, speed = 1) plays one animation.
  • AddBlendState(name, parameter, points) blends several by a number. Each point is {animation, value}. At a point's value its animation plays alone; between two points they share the weight.

The animator starts in the first state added. A non-looped state holds its last pose until the animator leaves.

Transitions. AddTransition(from, to, conditions, fadeTime = 0.2, exitTime?). from can be "*" for any state. It's taken once every condition holds:

  • {parameter, op, number} with >, <, >=, <=, ==, ~=
  • {parameter, "==" or "~=", true or false}
  • {trigger}: holds once SetTrigger(trigger) was called, and is used up by the transition that takes it

exitTime holds the transition until the state is that far through its first animation (1 = once through). The first transition that can go, in the order added, wins. At most one per frame.

Parameters. SetNumber, SetBool, SetTrigger, ResetTrigger. Unset numbers are 0 and unset flags false.

Reading it. CurrentState, StateChanged(from, to), GetStateWeight(name) while fading, and GetBlendWeights(name) for a blend state's shares in order of value. SetState(name, fadeTime) jumps to a state regardless of transitions.

The animator plays its states as Core tracks, so tracks you play at a higher priority go on top. States and transitions are set from scripts and not saved.

IK ​

An IKControl bends a chain of the model's bones so its end reaches a target: feet on steps, a hand on a handle, a head that looks around.

luau
local foot = Instance.new("IKControl")
foot.ChainRoot = "LeftUpperLeg"
foot.EndEffector = "LeftFoot"
foot.Type = Enum.IKControlType.Position
foot.Target = footTarget
foot.Pole = kneeTarget
foot.Parent = hero
PropertyIs
ChainRoot, EndEffectorFirst and last node of the chain, named as in the model file
TargetA part, model or attachment, moved by Offset
TypeTransform (go to the target and match its rotation, default), Position, Rotation (only the end turns) or LookAt (the chain turns so its rest-pose front faces the target)
PoleFor a two-bone chain like hip to ankle, a part or attachment in front of the knee to bend towards. Longer chains are solved iteratively
Weight0 to 1, blending from the animated pose to the solved one
EnabledOff switch
PriorityHigher is solved later, so it wins where chains share nodes

MeshPart:GetNodeTransform(name) gives a node's world transform as posed right now, for attaching things to a hand or head.

Limits ​

Scene:Raycast hits the posed model, but shape casts use the box, and ray-traced shadows use the rest pose.

Apache License 2.0