Skip to content

Tutorials · Animation and Cutscenes · Chapter 10

Reaching

25 minutes Uses: Ik, pulse_by, vec2

By the end

  • IK on hand_right, a chain of three that reaches for the lantern’s light and, out of its reach, points at it
  • IK on both legs and both feet, reaching for marks on the boards, so the knees bend outward and the soles stand flat through the idle’s sag
  • tap.rgs on mark_right: a target a script moves, which the right foot follows
  • The base layer’s clips keying the chains on in idle and off in dance
On this page

A hand that goes where it is told

A clip says where each bone turns. It does not say where the hand ends up, and that is what an arm reaching for a lantern is: the hand’s place first, and whatever the elbow and the shoulder must do to get it there. IK, inverse kinematics, is the other way round. You name a target and a chain of bones, and each step the bones turn so that the chain’s tip is on the target, or as near as the bones reach.

It goes on the node at the tip of the chain, here the hand. It is solved last in a step, after the scripts and after the layers, so a target that a script moved this step is reached this step, and on the bones of its chain it has the last word.

Reaching for the lantern

The lantern in the right wing has a light under it, a node called lantern_light, and it swings (chapter 3). The marionette’s right hand is the tip of a chain of three bones: the hand, the forearm and the upper arm.

  1. Select hand_right, click Add component and choose IkComponent.
  2. Set Target to lantern_light and Chain to 3. Leave Bend on Positive and Weight at 1.
  3. Untick Enabled. The idle will switch it on in the third section, and the dance will switch it off again.
The editor in Play, looking through the game camera at the wings, with hand_right selected and its Inspector narrowed with the search box, ik, to its IkComponent: Target lantern_light, Chain 3, Bend Positive, Weight 1.000 and Enabled ticked. The Viewport shows the marionette on its cross with both arms raised, a dashed violet line running from its right hand up to the lantern’s light near the top of the picture, and the knight standing to the right of the marionette; the toolbar reads Stop, Pause and Step
The right hand’s chain in Play, the knight walked to the wings and the idle having switched it on. The dashed line is the chain’s way to its target.
Target
The Ik’s Target: the name of the node the chain reaches for. It is found by name, anywhere in the scene, the first node with that name. Choose a node that is not in the rig, so that nothing in the rig carries it away: a light, or a mark on the boards.
Chain
The Ik’s Chain: how many bones it covers, counting its own node’s and then its parents, from 1 to 16. 3 on the hand is the hand, the forearm and the upper arm. A chain of one bone turns that bone to point at the target. Two is a limb, which can fold in the middle. More is a tail. A new IK’s is 2.
Bend
The Ik’s Bend: which way a two-bone chain folds, Positive or Negative. It matters only to a chain of two; the arm’s is three, so its Bend stays as it comes, Positive. The legs, below, fold their knees one way each.
Weight
The Ik’s Weight, from 0 to 1: how much of the pose the chain works out is applied. 1 is all of it, 0 none, and between the two the clips’ pose and the reached pose are mixed. The arm’s is 1. The legs’ and the feet’s are 0 as they are saved, and the idle keys them to 1.
Enabled
The Ik’s Enabled: whether the chain runs right now. Unticked, it does nothing, whatever its Weight. The arm’s is unticked as it is saved, and the idle keys it on.

Feet on the boards

Chapter 9’s idle sinks the whole body three units, and the legs sink with it. The same tool puts the feet back. A leg is a chain of two, the shin and the thigh, and its tip, the ankle, is told to reach for a mark on the boards that the body does not carry. As the body sags the knees bend outward, and the ankle stays where the mark is.

  1. Select theatre, click + Add node and choose Node. Rename it mark_left and set its Position to 1136.26, 282. Select theatre again and do the same for mark_right, at 1143.74, 282. They are where the ankles stand, a foot’s length above the boards.
  2. Select mark_left, click + Add node and choose Node. Rename it sole_left and set its Position to 0, 6. Do the same under mark_right for sole_right. A foot is 6 long, so each is one foot below its mark, which is where its sole should be.
  3. Select lower_leg_left, click Add component and choose IkComponent. Set Target to mark_left, Bend to Negative and Weight to 0. Chain stays 2 and Enabled stays ticked. Do the same on lower_leg_right with Target mark_right, and Bend left as it comes.
  4. Select foot_left and add an IkComponent with Target sole_left and Weight 0. Do the same on foot_right with Target sole_right, Bend Negative and Weight 0.
lower_leg_left selected and framed, its Inspector narrowed with the search box, ik, to its IkComponent: Target mark_left, Chain 2, Bend Negative, Weight 0.000 and Enabled ticked. The Viewport shows the shin and the leg beside it very close up, the shin outlined in blue with its bone drawn as a thin violet kite from a handle at its top to a small blue square at its tip
The left shin’s chain, as it is saved. Weight is 0 until the idle keys it.

The feet have chains of their own. A foot’s chain is the foot and its shin, folding at the ankle, and it reaches for the sole’s spot, one foot below the ankle’s mark. That is what lays the foot flat: a foot that points straight down stands on its sole. The ankle folds the opposite way round from the knee, so each foot’s Bend is the opposite of its leg’s.

The right foot is to tap. Its mark is the thing that moves, so the script goes on mark_right, and the foot follows it. Add a script called tap: in Assets press Create, choose New script, type tap and press Enter. In the Code tab, replace everything in tap.rgs with the script below, press Ctrl+S, and add the Tap component to mark_right.

rgs tap.rgs
/// The spot the marionette's right foot reaches for: it rises and falls for
/// good, so the foot taps the boards.
component Tap {
    fn on_create() {
        pulse_by(vec2(0.0, -5.0), 0.3, .OutQuad);
    }
}
on_create
A hook that runs once, when its node is made. The pulse it starts goes on after it.
pulse_by
Moves this node by a vector and back, for ever, taking the number of seconds each way. Here it is up 5 units, 0.3 seconds up and 0.3 down, so a round takes 0.6. The vertical axis runs down, so up is -5. It starts a pulse and returns at once.
vec2
Makes a vector of two numbers: vec2(0.0, -5.0) is no way across and five up.
.OutQuad
The curve of the move: quick at the start of each way and slowing as it arrives, as a foot lifts and settles. Chapter 6 lists the curves.
Close up of the marionette’s legs from the hips down: the knees bent outward, both feet flat and level, their soles on the boards’ top edge
The same moment as chapter 9’s feet, step 468, 7.8 seconds in: with the chains the soles stand on the boards, flat.

Keyed on and off

The chains are always there. They should work only when the marionette rests. In the dance the legs are meant to kick and the right arm to swing, and a chain that held the ankle on a mark would flatten both. The base layer decides which clip plays, so its clips switch the chains: idle keys them on, and dance keys them off.

  1. Select marionette, open the Properties mode of the Animation tab, open the clip idle and turn Record on.
  2. With the playhead at 0, select hand_right and tick the Enabled of its IK. Select lower_leg_left and set the Weight of its IK to 1, and do the same on lower_leg_right, foot_left and foot_right. Each edit is a key in idle.
  3. Open the clip dance and key the same five at 0 with the values the chains are saved with: Enabled unticked and each Weight 0. The Inspector already shows those, and an edit that changes nothing keys nothing, so tick Enabled and untick it again, and set each Weight to 1 and then to 0. The second edit replaces the first.
  4. Each of the ten new rows begins on Linear. Open its interpolation menu and choose Step.
  5. Press Capture RESET, so that the RESET clip knows the five as the chains are saved. Turn Record off, press Save in the bar, and press Ctrl+S.
ClipTrackMode0
idlehand_right enabledStepticked
lower_leg_left weightStep1
lower_leg_right weightStep1
foot_left weightStep1
foot_right weightStep1
dancehand_right enabledStepunticked
lower_leg_left weightStep0
lower_leg_right weightStep0
foot_left weightStep0
foot_right weightStep0
RESETthe same fiveLinearunticked and 0
The Animation tab on its Properties mode with marionette selected. The clip tabs read dance, RESET, idle, wave and breath, with idle lit, and the playhead reads 0.00 s. Eight rows: torso translation and bar translation on Cubic and head rotation on Linear (angle), each with three diamonds at 0, 1.5 and 3, and then hand_right enabled, lower_leg_left weight, lower_leg_right weight, foot_left weight and foot_right weight, each on Step with one diamond at 0
The idle clip. The last five rows, hand_right enabled to foot_right weight, are the chains’ switches.

The chains as built

The IK components

NodeTargetChainBendWeightEnabled
hand_rightlantern_light3Positive1unticked
lower_leg_leftmark_left2Negative0ticked
lower_leg_rightmark_right2Positive0ticked
foot_leftsole_left2Positive0ticked
foot_rightsole_right2Negative0ticked

The marks

NodeUnderPositionComponent
mark_lefttheatre1136.26, 282
sole_leftmark_left0, 6
mark_righttheatre1143.74, 282Tap
sole_rightmark_right0, 6

Every other field of every node is as it comes. The keys are in the table of the third section.

Check it works

Seven frames side by side, each the top of the marionette on its cross with both arms raised and the lantern on its chain above it, at the top of the frame. The lantern swings from the left end of its arc in the first frame to the right end in the last. The marionette’s arm at the right of the picture stays pointing up at it from end to end, leaning a few degrees further to the right as the light goes right; the other arm is raised and bent, waving
The reach, seven frames 15 steps, a quarter of a second, apart, from step 450 to step 540, which is 7.5 to 9 seconds in: the lantern swings from one end of its arc to the other and the arm follows it.
Eight frames of the marionette’s legs from the hips down to the boards. In the first both feet are flat on the boards and the knees are bent outward. In the next six the foot at the right of the picture lifts, flat, a little way off the boards, its shin and knee following it, and sets down again; the foot at the left stays where it is
The tap, eight frames 5 steps apart, from step 396 to step 431, which is 6.6 to 7.18 seconds in: the right foot rises with its mark and comes down.