Animation
Updated
Animation is everything in a world that moves on its own: a character that walks and waves, a door that swings open, a camera that flies through a hall, a tail that sways as a fox runs. MIRA animates entities with a small set of components, each with one job, that combine freely on one entity. A Behavior script drives them: it plays and stops animations, reacts when they finish, poses individual bones, and tweens any number it can reach. This section explains each piece, how they fit together, and how to control them from code.
Key concepts
Section titled “Key concepts”- Animation Clip. A component that plays the animations stored inside a loaded model file, such as a character’s
Idle,WalkorWave. You do not author these in MIRA; they come with the model. - Animation Timeline. A component that animates its own entity along keyframes you author: position, rotation, scale and visibility. It can also send signals at set moments.
- Layer. One playable animation. On an Animation Clip, each clip of the model is a layer; on an Animation Timeline, each authored group of tracks is a layer. Every layer is played with the same calls:
play,stop,pause,resumeandseek. - Animation Graph. A state machine. It holds named states (such as
IdleandWaving), runs layer actions as it enters and leaves them, and moves between states when a signal arrives. - Signal. A named message on the scene’s bus, such as
door/open. Signal Emitters, scripts (emit) and timeline signal keys send them; graphs and scripts (on) listen for them. - Skeleton and Morph. Components that hand a model’s bones and blend shapes (morph targets) to your scripts, so you can turn a head or open a jaw from code.
- Dynamic bones. Components that give bones secondary motion: they lag, overshoot and settle after the model moves, like hair, ears or a tail.
- Tween. A script global that animates any object’s numbers over time, such as an entity’s position, without authoring anything.
How it works
Section titled “How it works”Layers: one way to play
Section titled “Layers: one way to play”Clips and timelines expose their animations as layers, and every layer takes the same calls. A script, or an Animation Graph, plays a model clip and a keyframe layer the same way:
self.parent.getComponent(AnimationClipComponent).layer('Walk').play({ fade: 0.3 });self.parent.getComponent(AnimationTimelineComponent).layer('open').play();layer(name) returns one layer, or undefined when there is none yet. layer() with no name returns every layer as one: each call goes to all of them.
The two kinds differ in their defaults. A clip layer crossfades from the previous clip over 0.2 seconds when you give no fade, and repeats as the component’s repeat prop says. A timeline layer plays at once and plays once unless the call says otherwise.
Who starts playback
Section titled “Who starts playback”- An Animation Clip with
autoplay(on by default) plays itslayerprop, or the model’s first clip, as soon as the model loads. - An Animation Timeline with
autoplay(off by default) plays itslayerprop, or its first enabled layer, as its entity starts. - For more than one layer, or a layer that starts later, a script or a graph state plays it.
An enabled Animation Graph takes over. In play, while an enabled graph is on the entity, only its states play the entity’s layers, and the autoplay of the clip and the timeline plays nothing. Switch the graph off and the clip autoplays again.
The order of a frame
Section titled “The order of a frame”Each play frame, after the physics step, animation updates in a fixed order:
- Animation Timelines advance every running layer.
- Components advance: each Animation Clip moves its model, and Animation Graphs count down transition delays. Tweens and
delaytimers also advance before scripts. - Behavior scripts run their
update(dt). - Dynamic bones solve, last.
This order has consequences you can rely on:
- A pose you write on a bone or a morph target in
updatewins over a clip that frame, because the clip has already written it. Write it every frame to hold it over a playing clip. - Dynamic bones swing about whatever the clip and your script posed this frame.
- Your script sees this frame’s timeline poses and tween values.
A frame longer than 1/12 of a second counts as 1/12 of a second, so a stall shows as a short slow-down rather than a jump.
Hidden content does not animate
Section titled “Hidden content does not animate”Model animation stops while the entity is not on screen: it or a parent is disabled or hidden, or it is an LOD level that is not shown.
- An Animation Clip stops advancing and carries on from where it was when the entity shows again. It still counts as playing, and its
repeatandfinishedevents come only once it shows. - Dynamic bones stop solving and start again from rest.
- Animation Timelines keep playing while their entity is hidden, so a timeline can be what shows or hides it. Switching the entity off stops its timeline layers and puts their values back.
Editor and play
Section titled “Editor and play”Animation is mostly a play-mode affair. In the editor, a clip plays only while its entity is selected, timelines play nothing (the timeline tool previews them), graphs never run, and dynamic bones swing only while their entity is selected. Test your animation scripts in Play or Preview.
Networking
Section titled “Networking”Animation plays locally on each client: timeline layers, graph states and bone poses are not sent over the network. To keep a model’s clip settings in step between visitors, replicate the Animation Clip’s props with the NetworkTraitType.AnimationClip trait. See Multiplayer.
Your first animation
Section titled “Your first animation”This walkthrough plays a character’s walk clip and switches back to idle when the player stops pressing a key.
-
Add a model entity (for example a glTF model) with a character that has
IdleandWalkclips. Name itHero. -
Add an Animation Clip component to it. Leave
autoplayon and setlayertoIdle, so the character idles as soon as it loads. -
Add a Signal Emitter to the same entity with
signalset tohero. It forwards the clip’s events, such asAnimationClip::ready, to scripts. -
Add a Behavior to the entity with this script:
WalkOnKey.jx #pragma lifecycle(startup, update)const anim = self.parent.getComponent(AnimationClipComponent);let walking = false;let ready = false;function startup() {// The model may already be loaded, or may load later.ready = anim.mixer !== undefined;on('hero', (event) => {if (event.eventType === EventType.AnimationClip.Ready) ready = true;});}function update(dt) {if (!ready) return;const wantsToWalk = Input.keyboard.isKeyPressed(Key.W);if (wantsToWalk === walking) return;walking = wantsToWalk;anim.layer(walking ? 'Walk' : 'Idle')?.play({ fade: 0.25 });} -
Enter Play and hold W. The character blends into its walk; release the key and it blends back to idle.
The script keeps the component in a variable, waits until the model’s clips exist, and only calls play when the wanted state changes. Calling play every frame would restart a one-shot clip each frame; tracking the state avoids that.
Your first animation: a character idles, blends into its Walk clip while W is held and back to Idle when it is released, with an Animation Clip and its layers.
Click the view so it has the keyboard focus, then hold W to walk and release it to stop.
Choosing
Section titled “Choosing”| If you want… | Use | Read |
|---|---|---|
| A character’s walk, run or idle from its model file | Animation Clip | Animation Clip |
| Authored motion: a door, a camera fly-through, a light sweep | Animation Timeline | Animation Timeline |
| Signals at set times of an animation | Signal keys on a timeline | Animation Timeline |
| Switch animations when something happens | Animation Graph | Animation Graph |
| Aim a head, open a jaw, set an expression from code | Skeleton and Morph | Skeleton and morphs |
| Hair, tails, ears or antennae that react to motion | Dynamic bones | Dynamic bones |
| Animate any number once, from a script, without authoring | Tween and Ease |
Time and tweens |
| Slow motion or a pause for the whole game | Time |
Time and tweens |
In scripts
Section titled “In scripts”| Global | What it is |
|---|---|
AnimationClipComponent | Owns all animation playback for a model-backed entity. The host (e.g. MeshEntity) loads the model and hands the root + clips over via bind; this component builds the AnimationMixer, drives it each frame, and (in editor mode) overlays a skeleton helper when editor gizmos are shown. |
AnimationTimelineComponent | Keyframe animation of its entity's props, in layers of tracks, played by the runtime's animation system: one clip and action per layer, one keyframe track per track, on this timeline's own mixer, which the app's one clock (AnimationTimelineService) advances. A data component: the timeline tool reads and writes its props. |
AnimationGraphComponent | A state machine over its entity's animation layers: each state runs actions on layers as it is entered and left; transitions move between states on bus signals only: a timeline's signal track (to move on as a layer reaches a time, or its end), a Signal Emitter's, a script's emit. |
SkeletonComponent | The bones of its entity's loaded model, the real THREE.Bones, to read or pose from a script: |
MorphComponent | The morph targets (blend shapes) of its entity's loaded model, as channels a script sets: |
DynamicSkeletonComponent | The model's skeleton as a whole: in marks mode, moves the bones the model itself marks (Blender custom properties, exported as glTF extras, in the convention of the wiggle library, and wiggleLockX, wiggleLockY, wiggleLockZ for a bone's locks); in explicit mode, only the bones its Dynamic Velocity and Spring Bones name, each with its own settings. Scales every velocity bone's velocity and, in the editor, shows every moving bone of the entity while it is selected. An enabled bone component naming a bone wins over the model's marks for it. One per entity. The host passes the loaded model root to bind. |
DynamicSpringBoneComponent | A bone that springs after its parent's motion, overshooting and settling: tails, jiggle, antennae on a spring. |
DynamicVelocityBoneComponent | A bone that follows its parent's motion softly, at its velocity: hair, ears, antennae. |
DynamicBoneComponent | Base of every dynamic bone: self.getComponents(DynamicBoneComponent) lists the velocity and spring bones. |
Tween | Animate any object's numbers: Tween.to(mesh.position, { x: 5 }, { duration: 1 }), from, value, stop; awaitable. |
Ease | The easings, for { ease: Ease.OutCubic }: Linear, and In, Out and InOut of each curve (Quad, Cubic, Quart, Sine, Expo, Back, Elastic, Bounce). In starts slow, Out ends slow, InOut does both; Back overshoots a little, Elastic springs, Bounce bounces. Any function of progress 0..1 works as well. |
Time | Measure with Time.now(), Time.since(start); game time: Time.scale, pause(), resume(), isPaused(). |
Components
Section titled “Components”| Component | Type | What it does |
|---|---|---|
| Animation Clip | comp-animation-clip | Plays the animation clips built into a model. |
| Animation Graph | comp-animation-graph | State machine that switches animations on signals. |
| Animation Timeline | comp-animation-timeline | Keyframe animation of the entity's props, in layers. |
| Dynamic Skeleton | comp-dynamic-skeleton | Automatic secondary motion for a whole skeleton's marked bones. |
| Dynamic Spring Bone | comp-dynamic-spring-bone | One bone springs and overshoots: tails, jiggle. |
| Dynamic Velocity Bone | comp-dynamic-velocity-bone | One bone softly follows its parent: hair, ears. |
| Morph | comp-morph | Sets initial weights for this model's blend shapes and exposes live channels to scripts. |
| Skeleton | comp-skeleton | Lets scripts read and pose this model's bones, with optional humanoid bone mapping and limb chains. Shows the skeleton while the entity is selected. |
In this section
Section titled “In this section”| Topic | Description |
|---|---|
| Animation Clip | Play, crossfade, pause and scrub the clips built into a model, and react when they repeat or finish. |
| Animation Timeline | Keyframe layers on position, rotation, scale and visibility, with signal keys at set times. |
| Animation Graph | A state machine that plays clip and timeline layers when signals arrive. |
| Skeleton and morphs | Read and pose bones, map humanoid joints, and set blend shapes by name. |
| Dynamic bones | Secondary motion for hair, ears and tails: velocity bones, spring bones and the Dynamic Skeleton. |