animation.module
This package holds more than this page lists. See all of its files in its world.
README.md
animation Module
Public Luau surface over the __animation Internal FFI namespace — the engine's
animation observation, and ragdolls. Auto-injected as _G.animation via the
prelude.
Observing what is animating
animation.observe() answers "what is this engine posing right now, and why is
a body not moving" in one read. It reports the ENGINE's own measurement of the
pose landing on each armature, which is what makes it different from reading a
ClipPlayer's fields back: those carry what content asked for, and playing is
the value whoever attached the component wrote there. Every body report carries
both — the measured pose beside the clips the animator declared — so the two
are compared rather than confused.
animation.observe() -> AnimationObservation— the whole surface in one call:{ sampledAtMs, frame, bodies, animatingCount, riggedBodyCount, motionWindowMs }.animation.bodies() -> { AnimationBody }— every body the engine holds animation state for.animation.animating() -> { AnimationBody }— the ones whose pose is changing.animation.body(entityId) -> AnimationBody?— one body. Accepts a character root and answers for the skinned body under it.animation.whyStill(entityId) -> (reason, detail)— the one cause a body is not moving.animation.clips(entityId) -> { AnimationClip }— the clips contributing to its pose, with playheads.animation.coverage(entityId) -> (matched, total)— how many of the body's bones the clips driving it reach.
The verdict, and where it comes from
body.animating is read off body.pose, which the engine measures where a pose
lands on the armature:
pose.applies— poses that reached the bones.pose.revision— poses whose values differed from the one before. A body being animated advances this every frame.pose.sinceChangedMs— how long ago the values last differed. UndermotionWindowMs, the body is animating.pose.bonesWrittenofpose.bonesRequested— how much of the pose found an armature entity to land on.
body.reason names why a still body is still, from a closed set: deactivated,
noRiggedSkeleton, noGraph, clipUnreadable, noOutputNode, retargetPending,
retargetMatchedNoRoles, stopped, finished, paused, poseNotApplied,
poseUnchanged.
Retarget coverage
clip.matched of clip.total is what the engine computed when the clip was
bound to the body's rig. A humanoid clip on a humanoid rig reads 41 of 50; a
clip from an unrelated rig reads 0 of 50 while its playhead advances and the
body stands in its rest pose. clip.unmatched names the bones left at rest, up
to twelve of them.
Declaring a custom animator
The shipped animators — ClipPlayer, the character controller's locomotion, the
animation toolbox — all drive @builtin::systems.anim.AnimGraph, whose
:tick publishes through AnimGraph:publish, which declares only what changed
since the graph last declared. An animator that poses a body its own way calls
animation.declare(entityId, facts) and animation.forget(entityId) when it
releases the body. A clip whose facts name its sampler (the handle
skeleton.bindClip returned) reports the playhead that sampler last sampled at,
and every sample keeps the declaration current, so such an animator declares
when what it runs changes; one declaring clips without their sampler declares
on every frame it runs. Each body's declaredFrame names the observation frame
its driver last declared on.
How often a body is posed
A body's pose is evaluated as often as the views need it. Each frame, before any animator runs, the engine tests every rigged body against every view (the viewport camera and each enabled camera rendering into a texture) and gives it an interval in frames:
- In view, the interval its screen size names: every frame while it is large
on screen, every few frames as it shrinks (the settings'
steps). - Out of every view with its shadow in one (cast from the sun or any light whose shadows are on), the interval its screen size names, as in view.
- In no view, its shadow in none, every
offscreenIntervalframes (by default 120, the longest interval the settings take), unless it stands withinnearDistancemetres of a view, where it stays at every frame. - While its ragdoll owns its pose or hands it back, every frame, and on the frame the ragdoll lets go.
- Coming into view (itself or its shadow), or moving to a shorter interval, it is posed on that frame.
On the frames between, its animator writes nothing and carries the time
forward, so the body holds its pose, its bones are not written, and the
skinning pass reads the vertices it already holds; the next evaluation
advances by all the carried time. A change made in between lands on the
animator as it stands then: a graph first spends the time it carried on
itself as it was (AnimGraph:crossfadeTo, :setOutput, :play / :stop,
and AnimGraph:settle() before changing a node's playhead directly; the
engine's graphs do it for every change), and AvatarAnimator dates a
parameter or an emote when it was set, so a clip or state started while the
body was held plays from that moment, and the body comes back into view at
the pose an animator evaluated every frame shows. AnimGraph:state() and
AvatarAnimator:layers() read the animator at the time it stands at now.
AnimGraph:tick, the graphs the engine runs (ClipPlayer, Locomotion) and
AvatarAnimator all follow it; a custom animator asks animation.poseDue(id)
and does the same.
animation.poseRate(id) -> AnimationPoseRate?— one body'sintervalandreason(visible,near,shadow,offscreen,noView,disabled,override,ragdoll), itsscreenshare anddistance, and whether it isduethis frame. Also on each observed body asbody.rate.animation.poseRates() -> AnimationPoseRates— the crowd in total: bodies per reason, how many are posed every frame, theevaluationSharea frame makes against posing every body every frame, and thesettings.animation.setPoseRate(id, "exact" | "auto" | frames)— pin a body (and every skinned body belowid) to every frame, to a number of frames, or back to the views' choice. A character whose bones drive gameplay, attachments or physics off screen, or whose animator's passing time a script waits on there (a clip's end, a crossfade'sonDone, a state machine's second transition), is pinned"exact": those happen at a held body's next evaluation. It raises when no entity at or belowidcarries aSkeletonyet.animation.setPoseRateSettings({ enabled, steps, offscreenInterval, nearDistance, viewMarginDeg })— change how intervals are chosen; a field that cannot apply is refused by name.
A body posed every few frames still counts as animating: the observation's motion window grows by the frames between its evaluations.
Reading it as a file
The same document is served at /zero/runtime/animation, with one entry per
body under /zero/runtime/animation/bodies/<entity>. Both consumers read the
observation the engine publishes each frame, so they carry the same fields.
Ragdolls
animation.ragdoll(id, opts?) carries a skinned body's skeleton on physics
bodies: a death, a knockout, a hit reaction, a stunt fall, a crash-test dummy,
one limp limb. id is the skinned entity or any entity above it. A humanoid
gets bodies sized per body part and anatomical joints; any other rig gets a
capsule along every bone and ball joints.
animation.ragdoll(id)/animation.ragdoll(id, false): ragdoll the body, or hand it back to its animation. The first call builds the ragdoll on the next frame. Handed back, the bones blend from where they lie to the animated pose (for a body nothing animates, the pose it held when it fell) overblendseconds (default 0.5) and the entityidnames is moved to stand the body up where it lies (standUp = falsekeeps it where it is). A ragdoll poses the body whatever animation driver poses it.animation.ragdoll(id, { limp = { "leftarm" } }): only those bones and the bones below them go limp; the rest keep animating.animation.ragdoll(id, { mass = 75, bones = { head = { mass = 5, swing = 30 } } }): describe it: a total mass, and per boneshape,radius,length,size,mass,joint,swing,twist,hinge,strength,damping. On a humanoid a bone is named by its skeleton name or its humanoid role.animation.ragdollState(id) -> RagdollState?: every bone body with the entity it answers to, its shape, mass, pose, whether it is simulated, and its joint, plusproblems.animation.ragdollBone(id, bone) -> string?: the entity a bone body answers to. EveryPhysicscall takes it: joints, impulses, velocity,bodyState,contacts.
The physics guide's "Ragdolls" section (guides { path: "topics/physics" })
has the whole surface with examples.