Motion SDK

Walk Cycles

Walk a character with planted feet in a few lines, from the side, the front or three-quarters.

Hand-keying a walk means guessing every knee and foot, then checking a render. With rigging, the legs are IK chains and walk() keys only the goals: each foot is planted during its contact and arcs through its swing, and the body travels, bobs and sways. The feet can't slide, because a planted goal holds still and IK puts the ankle on it.

1. Rig the Legs

Give each leg bone joints (knee, ankle) and point its last joint at a foot goal with limb():

import { limb, svg } from "@motion-sdk/scene";

let hero = svg(art, {
  width: 2.4,
  bones: {
    "leg-l": { joints: [[102, 292], [102, 352]] },
    "leg-r": { joints: [[138, 292], [138, 352]] },
  },
});
hero = limb(hero, "leg-l", { target: "foot-l", bend: "ccw" });
hero = limb(hero, "leg-r", { target: "foot-r", bend: "ccw" });

From the side, bend picks the knee's side. From the front, give each knee a pole instead: an empty node in front of the knee (z toward the camera, parented to the body). The knee then bends toward the camera and a lifted foot shortens the leg on screen.

2. Walk

import { walk } from "@motion-sdk/scene";

const march = walk({
  feet: ["foot-l", "foot-r"],
  body: "hero",
  from: [0, 0.7],
  ground: -0.7,
  duration: 4,
  view: "front",
  stride: 0.4,
  cadence: 2,
  ankles: ["hero#leg-l.joint2", "hero#leg-r.joint2"],
});
// nodes: { ...march.nodes }, tracks: { ...march.tracks }, checks: checks(march.checks)
  • view: side travels along x (direction 1 or -1), front toward the camera (down the screen, by depth per step), three-quarter both.
  • stride (step length), cadence (steps per second) and stance (the share of each cycle a foot is down, default 0.62) set the rhythm.
  • lift, bob, sway and spread shape it. arms swing parts against the feet by armSwing degrees.
  • lift is how high each swing rises above its path (default 0.3 x stride from the side, 0.38 from the front, 0.35 at three-quarters). An orthographic camera gives no depth cue, so front views need the extra height: IK bends the knee toward the camera and the leg visibly shortens. A march wants more still; examples/ts/rig-walk.ts uses 0.34 on a 0.4 stride.
  • In front and three-quarter views the swing foot rises first and steps down the screen (toward the camera) late in the swing, and footScale (default 1.12) grows the ankles to that size at the top of each swing, back to 1 by the strike. Planted feet stay at 1 and don't move. footScale: 1 turns it off.
  • passHold (0 to 0.8, default 0.35) lingers on the passing pose: the swing slows through the middle, where the foot is highest, and speeds up at lift-off and strike.
  • ground is where the feet plant. Keep it a little less than a leg's length below the hips so the knees stay soft. A goal out of reach straightens the leg, and reaches catches it.

walk() returns nodes (the foot goals, with their plant windows), tracks (<foot>.walk, <body>.walk, <arm>.swing, and <ankle>.step for the foot scale), swings (each foot's whole swing windows, lift-off to strike) and checks: a planted check per window, on ankles if given.

3. Crowds

crowd([walkA, walkB, ...], { seed, jitter: { phase, cadence, stride } }) walks several characters with seeded offsets, so a column doesn't march in perfect lockstep. The same seed gives the same walk.

4. Check It

motion-sdk verify scene.json checks.json

planted fails with foot_slid when a foot slides more than 4 px during a window. lifts fails with low_lift when a swing doesn't rise far enough on screen:

...march.swings.flatMap((ws, k) => ws.map((during) => expect(ankles[k]).lifts({ during, min: 0.03 }))),

min is a fraction of the frame height (0.03 is about 32 px on a 1080 px canvas), measured from the higher of the swing's start and end. Add reaches for each ankle and attached for anything carried, such as a spear in a hand. examples/ts/rig-walk.ts passes all of them.