Skip to content

Tutorials · Animation and Cutscenes · Chapter 11

Cutting the strings

25 minutes Uses: PhysicalBone, Bone, AudioSource, Area, in_group, node, play_sound, ragdoll, set_param_flag, set_visible, wait

By the end

  • A Physical Bone on each of the marionette’s fourteen bones, sized to its limb, with Gravity 1200 and Damping 0.5
  • The rig’s rest pose captured from torso, so a rig that goes limp stands back up as it was built
  • An Area, an Audio Source and a script on marionette: the knight’s slash cuts its strings
  • A marionette that buckles, collapses and lies still when cut, and stands back at its rest pose five seconds later
On this page

A body for every bone

Until now something has always moved the marionette’s bones: a clip, a layer, a chain. A Physical Bone is the other way a bone moves. It gives the bone a body that gravity pulls on, and while that body is switched on the bone belongs to it: no clip, no layer and no chain moves a bone that has fallen. Switched off, the component does nothing at all, so the marionette dances and reaches exactly as it did.

The switch is the Physical Bone’s Limp, and a script turns it on. You will not tick it in the scene: a rig saved limp would begin every game lying on the floor. This section gives every bone a body. The next gives the rig a pose to stand back up in, and the one after gives it a blow that makes it fall.

  1. In the Hierarchy, make sure the whole rig shows under marionette. Select torso, then Ctrl-click the thirteen bones under it: head, upper_arm_left, lower_arm_left, hand_left, upper_arm_right, lower_arm_right, hand_right, upper_leg_left, lower_leg_left, foot_left, upper_leg_right, lower_leg_right and foot_right. Fourteen nodes are selected.
  2. Click Add component and choose PhysicalBoneComponent. It goes on all fourteen.
  3. With the fourteen still selected, set Gravity to 1200 and Damping to 0.5. What you set now is set on all of them. Limp stays unticked.
  4. Select torso alone and set its Size to 16, 16. Select head and set 14, 14.
  5. Select upper_arm_left, then Ctrl-click upper_arm_right, hand_left and hand_right, and set Size to 6, 6.
  6. Select both lower arms and set Size to 5, 5. Select both upper legs: 7, 7. Select both lower legs: 6, 6. Select both feet: 10, 12.
torso selected, its Inspector narrowed with the search box, physical, to its PhysicalBoneComponent: Size x 16.0 and y 16.0, Gravity 1200.00, Damping 0.50 with a slider, and Limp unticked; the Viewport shows the whole stage as it opens, a strip of the hall along its top with the marionette’s small figure selected at the right, over a dark field
The torso’s body: a 16 by 16 box, a pull of 1200, and Limp off.
Size
A Physical Bone’s Size: the box the bone has as a body while it is limp, in world units, centred on its joint and about as thick as the limb. It is a box on the joint, not the picture along the bone, so a bone that lies down rests on the boards at its own thickness. A new one is 8, 8. The torso’s is 16, 16, the head’s 14, 14, the limbs’ between 5 and 7, and the feet’s 10, 12.
Gravity
How hard a Physical Bone’s body is pulled down while it is limp, in world units a second a second. Down counts as positive here: a positive number pulls the bone to the boards. A new one is 900; the marionette’s is 1200, a brisk fall.
Damping
How much of its motion against its parent bone, and of its swing, a limp bone loses each step, from 0 to 1. 0 lets a limb swing on and on; 1 holds it dead against its parent. It is what settles a fallen rig instead of leaving it twitching. A new one is 0.2; the marionette’s is 0.5.
Limp
The switch. Ticked, the bone falls as a body pinned to its parent bone, and nothing else moves it; unticked, it is the rig’s again, and it stands back at its Bone’s rest pose. A scene keeps it unticked, and a script turns it on: the ragdoll call below does it for every bone at once.

A rest pose to stand up in

Going limp is the easy half. Standing back up is the other. When the script calls ragdoll(false), every bone goes back to its rest pose, the Rest Position, Rest Rotation and Rest Scale in its Bone. A bone keeps the rest it was added with, which is no pose at all, until you capture one, and the rig you built in chapter 8 never did. Left like that, it would stand up with every limb folded onto its parent’s joint. The editor already says so.

  1. Look at the Hierarchy: torso has a warning mark beside it, and the status bar at the bottom of the window says 1 problem. Click it: the Problems tab opens in the bottom dock.
torso selected with Look through on, so the Viewport shows the stage as the game camera sees it, a red valance over the hall and the knight small at the left; the dock’s Problems (1) tab lists one warning, on torso: This rig’s ragdoll stands its bones back up at their rest pose, and 14 of them never had one captured, so it would stand up in a heap, pose the rig as it should stand, then press Capture rest pose on this bone; in the Hierarchy torso carries a warning mark; the Inspector shows its Bone with Rest Position x 0.0 y 0.0, Rest Rotation 0.00 and Rest Scale x 1.0 y 1.0 over the Capture rest pose and Reset to rest buttons, then its Physical Bone, Size 16.0 and 16.0, Gravity 1200.00, Damping 0.50, Limp unticked; the status bar says 1 problem
For comparison, the rig before any rest pose is captured: a warning on torso, with the rest rows at their defaults.

The row is raised once, on the rig’s root bone, torso, the bone whose parent is not a bone. That is where the button goes, because it captures every bone at or under the node you press it on, and everything in the rig is under torso.

  1. Select torso. In its Bone, press Capture rest pose. The 1 problem in the status bar goes, and so does the warning. If you left Record on, leave it: it keys only what you edit in a row, never a button.
torso selected, its Inspector whole: its Node with Name torso, Position x 0.0 and y -55.3 and Rotation 90°; its Bone with Length 21.50, Rest Position x 0.0 and y -55.3, Rest Rotation 1.5708 and Rest Scale x 1.0 and y 1.0 over the Capture rest pose and Reset to rest buttons; its Physical Bone, Size 16.0 and 16.0, Gravity 1200.00, Damping 0.50, Limp unticked; the status bar says 1 node selected, and no problem
After Capture rest pose: the torso’s rest is where it stands.
Capture rest pose and Reset to rest
Two buttons in a Bone, each acting on every bone at or under the node it is pressed on. Capture rest pose copies where each bone stands now, its Position, Rotation and Scale, into its rest fields. Reset to rest does the opposite and puts each bone back at its captured pose, which is how you tidy a rig you have been posing by hand. Both are one undo step.
Rest Position
The Bone’s Rest Position: where the bone sits, in its parent’s space, when nothing is driving it. Capture copies the node’s Position into it, so torso’s is 0, -55.3, up from the marionette’s feet, and each limb’s is its joint’s place on its parent. A new Bone’s is 0, 0, which is why an uncaptured rig stands up in a heap. Nobody types it.
Rest Rotation
The Bone’s Rest Rotation, the rotation of its rest pose, shown in radians, the unit it is stored in; the node’s own Rotation, above it, shows degrees. torso’s is 1.5708, a quarter turn, the 90° above it; head’s is 3.1416, half a turn. Radians are degrees times about 0.01745.
Rest Scale
The Bone’s Rest Scale, the scale of its rest pose. It is 1, 1 on every bone of this rig, so Capture leaves it where it was, and a Bone starts there too.

Every bone now holds the pose it was built in. Nothing you typed produced them, and nothing about the rig looks different: they are what the rig goes back to.

The cut

What cuts the strings is the knight’s blade. His slash switches a hitbox on for two frames, chapter 4’s Area called blade, in the group blade. For the blade to cut anything, the marionette needs three things: an Area of its own for the blade to enter, a sound for the snap, and a script that listens.

The snap is chop.ogg from RPG Audio, the pack that gave you the curtain’s cloth and the slash’s swish. Copy it before the next step.

  1. Select marionette, click Add component and choose AreaComponent. Set its Shape’s Size to 24, 64 and its Offset to 0, -32. That is a box 24 wide and 64 high standing on the boards where the marionette stands. Its other rows stay as they come.
  2. Click Add component again and choose AudioSourceComponent. Leave Bus on Sfx and Autoplay off. Press + beside Triggers, open the new row, set Name to snap, and drag chop.ogg from Assets onto its Clip, as you did for the footsteps.
marionette selected, its Inspector narrowed with the search box, area, to its AreaComponent: the Shape open with Kind Rectangle, Size x 24.0 and y 64.0, an empty Outline, Step 32.00 u, Offset x 0.0 and y -32.0, and Solid and One Way unticked, then the Area’s own Layer, Mask and Track rows; the Viewport is framed on the marionette at 333.2%: its cross and three strings above its figure standing on the boards, a thin yellow box with small blue handles at its corners round the body from the feet up to the forehead, and a thin curve crossing at the left
The marionette’s Area, the yellow box: 24 wide, 64 high, standing on its feet.
marionette selected, its Inspector narrowed with the search box, audio, to its AudioSourceComponent: Clip none, Bus Sfx, Volume 1.000, Pitch 1.00, Looping and Autoplay unticked, the Spatial group open with Positional ticked, Max Distance 512.00, Blend 1.000, Rolloff Quadratic, Min Distance 0.00 and Pan 0.00, Max Voices 0, and under Triggers, one item, its row [0] open: Name snap, Clip chop.ogg, Clips with no items, Mode Shuffle, and its Pitch and Volume groups; the Viewport shows the same framed marionette
The snap: a trigger called snap, bound to chop.ogg.

Now the script. marionette.rgs already flips the dance on and off every three seconds, from chapter 9. It gains a base, two fields and a hook.

  1. Open marionette.rgs in the Code tab, replace everything in it with the script below, and press Ctrl+S.
  2. Select marionette. Its Marionette component has a new Strings row, empty. Click it and choose strings from the list, or drag strings from the Hierarchy onto the slot. The row shows the node’s name.
rgs marionette.rgs
/// The marionette's puppeteer: it rests three seconds, then dances three,
/// turn and turn about. A blade that reaches it cuts its strings: it falls
/// limp, and five seconds later it is strung up again, at rest.
component Marionette : Area {
    /// Seconds into this turn.
    #[hidden]
    clock: f32 = 0.0,
    /// Whether it dances this turn.
    #[hidden]
    dancing: bool = false,
    /// The strings a cut takes away.
    #[node_path]
    strings: i32 = 0,
    /// Whether its strings are cut.
    #[hidden]
    cut: bool = false,

    fn on_enter(other: NodeId) {
        if in_group(other, "blade") && !cut {
            cut = true;
            play_sound("snap");
            set_visible(node(strings), false);
            ragdoll(true);
            await wait(5.0);
            ragdoll(false);
            set_visible(node(strings), true);
            cut = false;
        }
    }

    fn loop() {
        clock += dt;
        if clock >= 3.0 {
            clock = 0.0;
            dancing = !dancing;
            set_param_flag("dancing", dancing);
        }
    }
}

component Marionette : Area says the script belongs on a node with an Area, and gives it the hooks an Area has, among them on_enter, which the engine calls when another Area starts overlapping this one, with that Area’s node as other. A field marked #[node_path] is a node picker in the Inspector; strings is the node you just picked, and cut is marked #[hidden], the script’s own memory, with no row.

When something enters the marionette’s Area, the hook asks whether it is in the group blade with in_group, which chapter 5 used for the spikes. Only the knight’s blade is: his own Area, which is in the group knight, passes through unnoticed. If it is the blade, the marionette is cut. play_sound, from chapter 5, plays the snap binding. The strings are hidden. ragdoll(true) turns every Physical Bone limp. Five seconds later ragdoll(false) stands them back up, and the strings are shown again. The loop hook, chapter 9’s, runs through all of it, so the dance’s clock goes on counting while the marionette lies there.

ragdoll
Turns every Physical Bone on this node and under it limp with true, and stands them back up with false. The run carries it out as the step ends, so the bones are bodies from the next step. ragdoll(false) also puts every Bone under the node back at its rest pose at once, so the rig is upright and at rest on the step it is called, not eased there.
wait
Suspends the hook for that many seconds, then carries on from the same line. It is awaited: await wait(5.0). While the hook waits, loop keeps running, and the hook is not entered again: a second blade that reaches the marionette while it is down starts nothing.
set_visible
Shows or hides another node, here the one node(strings) names, and the nodes under it go with it: the three strings. The node is hidden from the step the call runs on.
node
Turns the pick a #[node_path] field holds into the node the other calls take. A field with nothing picked is 0, which names nobody. The scene file keeps the pick as the node’s number, 31 for strings.

set_param_flag, in loop, is chapter 9’s: it flips the switch the base layer’s graph reads. Here is one cut, as the game plays it. The knight walks to the marionette and slashes; the strip starts a moment before his blade lands.

Seven frames of one cut, the marionette on its cross with the knight crouched at its left. In the first the strings run taut from the cross to its head and shoulders. In the second the knight lunges, a white arc of his sword at its waist, and the strings are gone, the cross left hanging. In the third the marionette still stands, one arm raised, its knees beginning to bend; in the fourth it squats with its knees out; in the fifth it sits down, leaning back; in the sixth and seventh it sits on the boards, an arm reaching forward and its legs folded, and the knight is no longer beside it
One cut at steps 270, 276, 282, 288, 296, 306 and 330 of a run, 4.5 s to 5.5 s of play. The blade lands between the first frame and the second, and the strings go with it. By the sixth frame, half a second later, it is down.

It falls from the pose it was in at that moment, the planted feet of chapter 10 and all, so a cut at another moment of its dance is a slightly different fall. Some end lying on the back, as this one does a little later; some end sitting up against their own legs. Either is right: the bodies decide.

Down, and back up

The bodies keep moving for a while, swinging and settling, and then they stop. From about 220 steps after the cut, three and two thirds seconds, every bone holds its place: the limp rig has come to rest on the boards, and the engine holds it there instead of letting it drift. These three frames are 36 steps apart, from 8.3 s to 9.5 s of the run, and they are the same picture.

Three frames, the same in each, of the fallen marionette at four times their size: it lies on its back on the boards, its head at the left and drawn a little into the boards, one arm folded up beside its head, its blue torso slanted up to the right and its legs bent beneath it
The marionette down, at steps 500, 536 and 572, 8.3 s, 8.9 s and 9.5 s of the run: not a bone has moved.

Five seconds after the cut the wait ends. ragdoll(false) stands the rig back up at its rest pose, at once, in one step, the strings come back, and the layers take the bones back from where the rest pose leaves them: the rig dances on from standing.

Seven frames of the marionette standing back up. In the first two it lies in a heap at the foot of the frame, with no strings from the cross above it. In the third it stands upright, its arms down along its body, its legs straight and its feet flat, the strings taut again. In the next four its arm rises on one side and its knees bend, and in the last its other arm sweeps out to the side
The stand at steps 570, 574, 576, 578, 582, 590 and 606, 9.5 s to 10.1 s of the run. It is down at 574 and upright at 576, five seconds, 300 steps, after the cut.

The bones, the rest pose and the cut

The physical bones

NodeComponentFieldValue
torsoPhysical BoneSize16, 16
headSize14, 14
upper_arm_left, upper_arm_rightSize6, 6
lower_arm_left, lower_arm_rightSize5, 5
hand_left, hand_rightSize6, 6
upper_leg_left, upper_leg_rightSize7, 7
lower_leg_left, lower_leg_rightSize6, 6
foot_left, foot_rightSize10, 12
all fourteenGravity1200
Damping0.5
Limpunticked

The rest pose, as Capture rest pose writes it

NodeRest PositionRest Rotation
torso0, -55.31.5708, the node’s 90°
head0, 03.1416, 180°
upper_arm_left3.5, 6.50
lower_arm_left13, 00
hand_left11, 00
upper_arm_right3.5, -6.50
lower_arm_right13, 00
hand_right11, 00
upper_leg_left21.5, 3.50.12, 6.88°
lower_leg_left15, 0-0.24, -13.75°
foot_left13, 00.12, 6.88°
upper_leg_right21.5, -3.5-0.12, -6.88°
lower_leg_right15, 00.24, 13.75°
foot_right13, 0-0.12, -6.88°

Rest Scale is 1, 1 on every bone. Capture rest pose wrote all of it: you typed none.

The cut

NodeComponentFieldValue
marionetteAreaShape Size24, 64
Shape Offset0, -32
Audio SourceTriggers, Namesnap
Triggers, Clipchop.ogg
MarionetteStringsstrings, kept as its number, 31
Cuthidden, false

Every other field of every node is as it comes.

Check it works