Dynamic bones
Updated
Dynamic bones give a model secondary motion: movement that is not authored but follows from other movement. When a fox runs, its tail lags behind, swings past and settles; when a character turns, its ponytail sways. The model moves, by a clip, a timeline, physics or a script, and its dynamic bones react on their own. Secondary motion makes characters feel alive at almost no authoring cost.
| Component | Type | Motion |
|---|---|---|
| Dynamic Velocity Bone | comp- |
One bone softly follows its parent: hair, ears. |
| Dynamic Spring Bone | comp- |
One bone springs after its parent, overshooting and settling: tails, jiggle. |
| Dynamic Skeleton | comp- |
The bones the model itself marks, a velocity scale for the whole model, and script access to every swinging bone. |
All go on a model entity (glTF, FBX, Collada, OBJ, USDZ or a kit piece). Add one velocity or spring bone component per bone, as many as you need, and at most one Dynamic Skeleton.
Before you start
Section titled “Before you start”- Dynamic bones act on a model’s skeleton; Skeleton and morphs explains bones and bone names.
- Dynamic bones solve last in the frame, after clips, timelines and scripts. See Animation.
- An entity can hold several bone components.
getComponents(DynamicSpringBoneComponent)lists them, and the base classDynamicBoneComponentfinds both kinds:getComponents(DynamicBoneComponent).
How a bone swings
Section titled “How a bone swings”Each dynamic bone chases where its tip would be at rest, and only rotates to aim at it: it is never re-parented or stretched.
- Follow or spring. A velocity bone closes in on its rest smoothly, at its
velocity. A spring bone behaves like a damped spring: with little damping it overshoots and oscillates; with a lot it creeps to rest without passing it. - Limited swing. A bone swings at most 75° from rest, so a model moved hard never folds through itself.
- Frame-rate independent. The motion is the same at any frame rate.
- Over clips and scripts. A clip or a script posing the bone this frame sets its rest, and the bone swings about it.
Properties
Section titled “Properties”Both bone components share these props:
| Prop | Type | Default | Description |
|---|---|---|---|
bone |
string | '' |
The bone’s name, as loaded or as in the modelling tool. It must have a parent. |
lockPosition |
{ x?, y?, z? } of booleans |
all false |
Model axes along which the tip cannot move. Missing axes are unlocked. |
A name that is not a bone logs a warning, and the component does nothing.
Dynamic Velocity Bone
Section titled “Dynamic Velocity Bone”| Prop | Type | Default | Description |
|---|---|---|---|
velocity |
number | 0.1 |
How fast it follows its parent, from 0.01 to 10. Lower follows more slowly. |
Dynamic Spring Bone
Section titled “Dynamic Spring Bone”| Prop | Type | Default | Description |
|---|---|---|---|
stiffness |
number | 500 |
Its pull back to rest, from 10 to 100000. Higher is snappier. |
damping |
number | 17 |
Its friction, from 0 to 10000. Higher swings less. |
mass |
number | 1 |
Its weight, from 0.001 to 1000. Higher is heavier and slower. |
Dynamic Skeleton
Section titled “Dynamic Skeleton”| Prop | Type | Default | Description |
|---|---|---|---|
mode |
'marks' | 'explicit' |
'marks' |
marks also swings the bones the model marks; explicit swings only the bones its velocity and spring bone components name. |
velocityScale |
number | 1 |
Scales the velocity of every velocity bone of the entity, from 0 to 10. Spring bones are not scaled. |
In marks mode, the Dynamic Skeleton swings bones that the model marks with custom properties set in the modelling tool and exported with the model: wiggleVelocity makes a velocity bone, wiggleStiffness (with optional wiggleDamping) makes a spring bone, and wiggleLockX, wiggleLockY, wiggleLockZ lock axes. A component naming the same bone wins over the model’s marks.
A Dynamic Skeleton is not required: velocity and spring bones work alone. Add one for the model’s marks, velocityScale, or script access to the swinging bones.
Locked axes
Section titled “Locked axes”lockPosition axes are the model’s own axes. They turn with the model and are the same for every bone.
lockPosition: { y: true }keeps the tip from moving along the model’s up axis: a model bobbing up and down never sets the bone swinging.lockPosition: { x: true, z: true }leaves only Y: the bone reacts to up and down motion alone.
A lockPosition edit replaces the whole object; omitted members become false.
Script members
Section titled “Script members”| Member | On | What it does |
|---|---|---|
reset() |
bone components, Dynamic Skeleton | Snaps the bones it moves back to rest now and clears their motion, for example after a teleport. |
bones() |
Dynamic Skeleton | Every bone of the entity that swings, marked or named by a component. The same array on every call. |
bone(name) |
Dynamic Skeleton | The swinging bone name; undefined when it does not swing. |
hasBones() |
Dynamic Skeleton | Whether any bone of the entity swings. |
velocityScale |
Dynamic Skeleton | The scale it applies: its own while enabled, otherwise 1. |
A pose you set on a bone from bones() or bone(name) becomes its rest: the bone swings about it.
Tuning
Section titled “Tuning”- Start from the defaults.
velocity: 0.1is soft and floppy; raise it toward0.3for a tighter follow.stiffness: 500, damping: 17, mass: 1give a lively, bouncy spring. - Bounce versus settle. A spring stops oscillating at about
damping = 2 × √(stiffness × mass), around 45 for the default stiffness and mass. Below that it overshoots; above it, it creeps back without passing rest. - Heavy or light. Raise
massfor a slower, heavier swing; raisestiffnessfor a quicker, snappier one. - Chains. Give each bone of a tail or a strand its own component. Lower velocities toward the tip, or softer springs, read as a whip.
- Unwanted bobbing. If walking makes ears or antennae flap, lock the axes they should ignore.
Examples
Section titled “Examples”1. A balloon dog with spring ears and a wagging tail
Section titled “1. A balloon dog with spring ears and a wagging tail”The bones are set up in the editor, with no code: the balloon dog model has a Dynamic Skeleton, a Dynamic Spring Bone on each ear bone (Bone2, Bone4, Bone8, Bone10, stiffness: 200, damping: 8) and a Dynamic Velocity Bone on each tail bone (Bone20 to Bone22, velocity falling from 0.2 to 0.1 toward the tip). An Animation Timeline on the dog has a Hop layer that moves it up and sideways. A Behavior under the dog only starts the hop:
#pragma lifecycle(startup)
function startup() { const timeline = self.parent.getComponent(AnimationTimelineComponent); timeline.layer('Hop').play({ repeat: 'repeat' });}A balloon dog hops on an Animation Timeline while Dynamic Spring Bones bounce its ears and Dynamic Velocity Bones swing its tail behind the motion.
Watch the ears bounce and the tail trail behind each hop. Drag to orbit the camera, scroll to zoom.
- The timeline moves the whole dog; nothing animates the ears or the tail. Their swing is the dynamic bones answering the motion.
- The ears are springs: they overshoot and bounce back each time the dog lands. The tail bones follow with velocity, softer toward the tip, so the tail trails behind like a whip.
2. Shake a springy stick
Section titled “2. Shake a springy stick”A model without any marks gets spring bones from a script, then is swung from side to side so its top lags and whips behind. The stick also carries a Skeleton, so selecting it in XR Creator draws its three bones over the mesh.
#pragma lifecycle(startup, update)
const stick = self.parent;let shaking = true;let phase = 0;
function startup() { // Softer toward the tip, so it whips. ['Bone.001', 'Bone.002'].forEach((bone, i) => { stick.addComponent(new DynamicSpringBoneComponent({ bone, stiffness: 300 - i * 120, damping: 6 })); }); log('Spring bones:', stick.getComponents(DynamicSpringBoneComponent).length);}
function update(dt) { if (Input.keyboard.isKeyReleased(Key.Space)) { shaking = !shaking; log(shaking ? 'Shaking' : 'Holding still'); } if (!shaking) return; phase += dt * 4; // only while shaking, so it resumes where it stopped stick.setPosition(Math.sin(phase) * 0.5, 0, 0);}A script adds Dynamic Spring Bone components to the bones of a loaded stick, then swings the stick from side to side so its tip lags and whips behind.
Watch the tip lag behind. Click the scene and press Space to stop the shaking and watch the stick settle. Drag to orbit the camera, scroll to zoom.
bonetakes the name as in the modelling tool:Bone.001loads asBone001, and either works.- The top bone gets the lower stiffness, so it swings more than the one below it.
damping: 6is low, so the stick wobbles for a while after Space stops the shaking.setPositionmoves the whole entity; the spring bones react to that motion on their own.phaseadvances bydtonly while shaking, so after a pause the swing carries on from where it stopped instead of jumping.
Snippets
Section titled “Snippets”1. Add a tail and ears from code
Section titled “1. Add a tail and ears from code”A script can give any loaded model secondary motion. This one adds a three-bone spring tail and two velocity ears to a fox.
#pragma lifecycle(startup)
function startup() { const fox = self.parent;
// A tail: softer toward the tip, so it whips. const tail = ['Tail_01', 'Tail_02', 'Tail_03']; tail.forEach((bone, i) => { fox.addComponent(new DynamicSpringBoneComponent({ bone, stiffness: 600 - i * 150, damping: 15, })); });
// Ears that ignore the up-and-down bob of running. for (const bone of ['Ear_L', 'Ear_R']) { fox.addComponent(new DynamicVelocityBoneComponent({ bone, velocity: 0.3, lockPosition: { y: true }, })); }
log('Dynamic bones:', fox.getComponents(DynamicBoneComponent).length);}- Each tail bone gets its own spring component; stiffness drops from 600 to 300 toward the tip, which reads as a whip.
damping: 15is below the critical value for these stiffnesses, so the tail overshoots and settles.- The ears use velocity bones with
lockPosition: { y: true }, so running up and down does not set them flapping. getComponents(DynamicBoneComponent)counts both kinds at once, because it is their shared base class.- The components bind as soon as the model is loaded, or once it loads, so the script does not need to wait.
2. Reset after a teleport
Section titled “2. Reset after a teleport”Moving a model instantly makes its dynamic bones swing across the jump. reset() snaps them to rest.
#pragma lifecycle(startup)
function startup() { on('fox/teleport', (spot) => { self.parent.setPosition(spot.x, spot.y, spot.z);
for (const bone of self.parent.getComponents(DynamicBoneComponent)) bone.reset(); self.parent.getComponent(DynamicSkeletonComponent)?.reset(); });}- Another script sends
emit('fox/teleport', { x: 0, y: 0, z: -10 }); the listener receives that object asspot. setPositionmoves the entity at once.- Every bone component, and the Dynamic Skeleton if there is one (the
?.skips it otherwise), clears its motion, so the tail and ears start from rest at the new place.
3. Heavier hair when wet
Section titled “3. Heavier hair when wet”Spring settings can change at runtime, but each change rebinds the model’s dynamic bones from rest. Change them on events, never every frame.
#pragma lifecycle(startup)
const DRY = { stiffness: 500, damping: 17, mass: 1 };const WET = { stiffness: 300, damping: 30, mass: 3 };let wet = false;
function setWet(value) { if (value === wet) return; // an equal edit would change nothing anyway wet = value; for (const spring of self.parent.getComponents(DynamicSpringBoneComponent)) { spring.setProps(wet ? WET : DRY); } log(wet ? 'Hair is wet' : 'Hair is dry');}
function startup() { on('weather/rain', () => setWet(true)); on('weather/sun', () => setWet(false));}getComponents(DynamicSpringBoneComponent)returns every spring bone on the entity.setPropswith three props at once makes one change, so the bones rebind once.- The heavier mass and higher damping make the hair swing slower and settle sooner, as wet hair does.
- The early return skips work when the state does not change.
4. Calm the swing while sprinting
Section titled “4. Calm the swing while sprinting”The Dynamic Skeleton’s velocityScale changes every velocity bone of the model together. This script lowers it while Shift is held and also reads the swinging bones.
#pragma lifecycle(startup, update)
const dynamic = self.parent.getComponent(DynamicSkeletonComponent);let sprinting = false;
function startup() { if (dynamic?.hasBones()) { log('Swinging bones:', dynamic.bones().map((b) => b.name).join(', ')); }}
function update() { if (!dynamic) return; const now = Input.keyboard.isKeyPressed(Key.ShiftLeft); if (now === sprinting) return; sprinting = now; dynamic.setProps({ velocityScale: sprinting ? 3 : 1 });}- A higher
velocityScalemakes velocity bones follow faster, so ears and hair stay tighter at speed. Spring bones are not affected. - The script calls
setPropsonly when the key state changes; calling it every frame would rebind the bones from rest every frame. bones()lists every swinging bone, whether marked in the model or named by a component.
Common mistakes
Section titled “Common mistakes”- Calling
setPropsevery frame. An effective prop change rebinds every dynamic bone of the model from rest. Change props on events. - A bone name that does not exist. The component logs a warning and does nothing. Check names with a Skeleton’s
bones(). - A root bone. The bone must have a parent; the model’s root bone cannot swing.
- Forgetting
reset()after a teleport. The bones swing wildly across the jump. - Expecting motion in the editor. Dynamic bones move in the editor only while their entity is selected; test in Play.
- Hidden models. A hidden or disabled entity solves nothing; its bones start again from rest when it shows.