Skip to content

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.

  • Animation Clip. A component that plays the animations stored inside a loaded model file, such as a character’s Idle, Walk or Wave. 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, resume and seek.
  • Animation Graph. A state machine. It holds named states (such as Idle and Waving), 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.

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.

  • An Animation Clip with autoplay (on by default) plays its layer prop, or the model’s first clip, as soon as the model loads.
  • An Animation Timeline with autoplay (off by default) plays its layer prop, 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.

Each play frame, after the physics step, animation updates in a fixed order:

  1. Animation Timelines advance every running layer.
  2. Components advance: each Animation Clip moves its model, and Animation Graphs count down transition delays. Tweens and delay timers also advance before scripts.
  3. Behavior scripts run their update(dt).
  4. Dynamic bones solve, last.

This order has consequences you can rely on:

  • A pose you write on a bone or a morph target in update wins 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.

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 repeat and finished events 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.

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.

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.

This walkthrough plays a character’s walk clip and switches back to idle when the player stops pressing a key.

  1. Add a model entity (for example a glTF model) with a character that has Idle and Walk clips. Name it Hero.

  2. Add an Animation Clip component to it. Leave autoplay on and set layer to Idle, so the character idles as soon as it loads.

  3. Add a Signal Emitter to the same entity with signal set to hero. It forwards the clip’s events, such as AnimationClip::ready, to scripts.

  4. 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 });
    }
  5. 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.

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
GlobalWhat it is
AnimationClipComponentOwns 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.
AnimationTimelineComponentKeyframe 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.
AnimationGraphComponentA 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.
SkeletonComponentThe bones of its entity's loaded model, the real THREE.Bones, to read or pose from a script:
MorphComponentThe morph targets (blend shapes) of its entity's loaded model, as channels a script sets:
DynamicSkeletonComponentThe 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.
DynamicSpringBoneComponentA bone that springs after its parent's motion, overshooting and settling: tails, jiggle, antennae on a spring.
DynamicVelocityBoneComponentA bone that follows its parent's motion softly, at its velocity: hair, ears, antennae.
DynamicBoneComponentBase of every dynamic bone: self.getComponents(DynamicBoneComponent) lists the velocity and spring bones.
TweenAnimate any object's numbers: Tween.to(mesh.position, { x: 5 }, { duration: 1 }), from, value, stop; awaitable.
EaseThe 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.
TimeMeasure with Time.now(), Time.since(start); game time: Time.scale, pause(), resume(), isPaused().
ComponentTypeWhat it does
Animation Clipcomp-animation-clipPlays the animation clips built into a model.
Animation Graphcomp-animation-graphState machine that switches animations on signals.
Animation Timelinecomp-animation-timelineKeyframe animation of the entity's props, in layers.
Dynamic Skeletoncomp-dynamic-skeletonAutomatic secondary motion for a whole skeleton's marked bones.
Dynamic Spring Bonecomp-dynamic-spring-boneOne bone springs and overshoots: tails, jiggle.
Dynamic Velocity Bonecomp-dynamic-velocity-boneOne bone softly follows its parent: hair, ears.
Morphcomp-morphSets initial weights for this model's blend shapes and exposes live channels to scripts.
Skeletoncomp-skeletonLets scripts read and pose this model's bones, with optional humanoid bone mapping and limb chains. Shows the skeleton while the entity is selected.
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.