| name | procedural-character-animation |
| description | Animate a humanoid character entirely from continuous state — no spritesheet, no clips, no blend tree — using a joint skeleton, forward kinematics and two-bone IK. Use when building locomotion, crouch/prone, climbing, ladders, aiming or melee for a side-view character, when a walk "slides" or "looks canned", or when you need to judge animation quality without being able to watch it. |
Animating a character with arithmetic
A pose is a list of ANGLES. The skeleton turns those into joint POSITIONS. The
drawing turns positions into pixels. Change the numbers and the drawing follows
for free — which is the whole reason to do it this way instead of drawing
frames, because a clip cannot answer "he is moving at 2.7 m/s, aiming 31° up,
three quarters of the way into a crouch", and that is the only question a
player ever asks.
Rule 1 — the phase is advanced by DISTANCE, not by time
phase += travelled / stride // NOT phase += dt * rate
A clip played at a rate is wrong the instant the rate changes, wrong on a
slope, and wrong in a slide. A phase driven by odometry cannot be. This is the
single line that stops the feet sliding, and foot slide is the one thing that
tells a player an animation is canned.
It also means a change of gear needs no blend: the phase is continuous through
it because the odometer is.
Rule 2 — the feet lead and the hips follow
The intuitive way round — swing the thigh, let the foot land where it lands —
slides by construction. Instead:
- Give each foot a TARGET. Planted, it is motionless in the world; swinging,
it arcs forward. While planted its position relative to the body moves
backward at exactly body speed, which is one line and is the whole trick.
- Put the pelvis at whatever height keeps the planted leg inside its own
length:
sqrt(L² - x²). The rise and fall of walking, and the dip through
double support, come out of the geometry. Never tune a bob.
- Solve the legs backwards from the feet with two-bone IK.
Rule 2b — a held object is the target, and the HANDS follow it
Rule 2 applied one level up. Pose the arms from joint angles and then draw a
weapon between the two hands, and everything is wrong for the same reason a
swung thigh slides: the hands are half a forearm apart, so a few degrees of
noise between them swings the muzzle thirty degrees, and nothing in the chain
knows what the character is aiming at. A line of men all shooting at the same
thing came out holding sticks at unrelated angles.
Invert it. Decide the aim direction, place the object along it, anchor it where
it is actually held (a rifle's buttpad sits in the shoulder pocket — anchor at
the grip and let it extend both ways and a quarter of a body length of stock
hangs out behind the spine, through the chest), then solve BOTH hands onto it
with two-bone IK, elbows biased down. Draw it from the same anchor and axis the
hands were solved to, so the thing on screen and the thing being held cannot
disagree.
Order matters and the fault is invisible in a still. The torso attitude —
lean, twist, neck — moves the shoulders, and the shoulders are what the arms
are solved FROM. Set them before solving the skeleton you IK against; set them
after and you rotate the upper body out from under hands that were placed a
moment earlier, differently for every character depending on his lean. The
symptom is weapons at inconsistent heights across identical poses, and it reads
as jitter in a transform rather than as the ordering bug it is.
Rule 3 — cadence is the primitive, stride is derived
cadence = f(speed) stride = speed / cadence
Modelling stride directly and dividing for cadence looks equivalent and is not:
it lets contact time grow with speed, and contact time × speed is exactly how
far a planted foot travels relative to the hips. At sprint that came out at
1.3 m of travel for a 0.9 m leg, so the geometry answered by putting the hips at
0.44 of leg length — a duck-walk, measurable long before it was visible.
Corollary: leg length and stride are coupled. Shortening the legs to fix
proportions will over-extend an existing stride and sink the hips. That is the
geometry telling you the stride was too long.
Rule 4 — the ankle rolls, and the roll constant lives in ONE place
A straight leg from a hip to an ankle pinned on the floor forces the hips down
at both ends of every step, and the figure squats along. Real ankles rise at
heel-strike and toe-off (about ⅛ of leg length); the toe stays planted while the
ankle pivots over it, so it costs no foot slide.
This constant is needed in two places — the stance solution and the flight
arc's take-off height — and the two disagreed twice, each time putting a step
of a fifth of a leg into the hips at the seam. Put it in one function.
Rule 5 — flight is ballistics, not a number that looked right
A body in free flight for t seconds rises g·t²/8, where t is the flight
window over the cadence. Inventing the height put twelve pixels of rise into a
window three hundredths of a second wide at the walk/run boundary — a pop, at
exactly the moment the gait changes character. The true answer was one pixel; a
sprinter's centre of mass really does only rise a couple of centimetres.
Rule 6 — a walk and a run differ by ONE number
Stance fraction: the share of the cycle each foot spends on the ground. Above a
half, both feet are down for part of the cycle and it is a walk. Below it there
is a window with neither and it is a run. Nothing else distinguishes them — not
speed, not amplitude. Six "gears" is one gait sampled at six speeds.
Rule 7 — every non-walking state needs its own geometry
Do not reach for the walk with the numbers turned down.
- Prone has no clearance under the pelvis, so the walk's foot targets are
unreachable and the IK folds the legs into the chest. Crawling is its own
gait: legs nearly straight BACK along the ground at almost full extension
(tucking them in leaves the knee nowhere to fold but through the floor),
arms reaching forward of the shoulder — relative to the pelvis they land
under his own chest, because prone the shoulder is a third of a body length
ahead of the hips.
- Prone heads must be solved absolutely, and it is the FACE you are solving,
not the skull. Inheriting the torso's lean when the torso is horizontal
means staring at the floor. But solving the skull to point forward points
the face at the floor too, because the face direction is PERPENDICULAR to the
skull's axis — to look ahead off a horizontal body the neck cranes and the
skull comes up toward vertical, which is what a man on his belly actually
does. Getting this wrong twice in a row costs two rounds of "still looking
down".
- A head held up off a prone body is the neck carrying it. Look ahead while
moving; let it down to rest when stationary, lifting occasionally to check.
Free, and it is the difference between a body and a mannequin lying down.
- Climbing: hang the body FROM the hands. They stay on the edge; the
shoulders sit however far below them the arms are extended; folding the arms
is what raises him. Setting
y along a curve and letting the arms follow is
the same thing backwards and looks exactly like a man being levitated past a
ledge. And put the feet on the wall — hand-posed legs that never touch
the surface are what make a climb read as a teleport with arm movement. Then
clamp those foot targets to the ground beneath him: on a knee-high crate the
"hang" position is below the floor, and the legs go into the terrain.
- A vault is not a slow climb. Below about half body height there is
nothing to hang from: you plant a hand, drive off the legs and step over the
top in one arc. Hanging off a knee-high crate looks like a man who has never
seen a crate. Pick the move from the obstacle's height above what he is
standing on, not from its height above the ledge.
- A kneel is the rear KNEE on the ground, and it is a contact point like a
foot. Solve for where the FEET go and let the knees land where they may —
the obvious approach, and the same mistake as swinging the thigh — and you
get two horizontal thighs and two vertical shins: a man sitting on an
invisible chair. Drop the pelvis until the thigh alone spans hip to floor,
put the rear foot back far enough that the shin lies along the ground, and
plant the front foot under the front knee.
- Ladders: four limbs IK'd to one vertical line, two beats out of phase,
with the phase advanced by distance climbed. Same principle as Rule 1.
Rule 7b — a death is a SIMULATION, not a pose function
Everything above is a pose function because a walk is a cycle and a cycle has a
parameter. A death is not a cycle: it never repeats, and what makes it read as
death rather than as an animation is that it answers to how the character was
standing, how fast he was going and which way he was facing at that instant.
So: a verlet ragdoll, its particles born on the joints of the pose he died in,
distance constraints for the bones, gravity, a floor. Nobody authors a
falling-over animation and nobody can, because there are as many of them as
there are ways to be standing. Two things that are not obvious:
- The impulse goes in as a difference between position and PREVIOUS position
— that is what velocity is in verlet. Setting the position instead teleports
the body a pixel and leaves it standing still in the air.
- The floor is a constraint too, so it goes INSIDE the relaxation loop.
Solving the bones and then clamping to the ground afterwards is the obvious
order and it is wrong: the clamp gets the last word every tick, so it can
pull a foot up while the hip stays put and leave that bone permanently over
length. Interleaved, worst drift went from 25% to 9%.
Rule 8 — measure it, because you cannot watch it
Animation is the one thing a screenshot cannot show, and an agent cannot watch
it at all. Assert on the properties a viewer would complain about:
- a planted foot does not move HORIZONTALLY (vertical movement is the roll)
- no knee ever bends backwards
- the hips never sink below ~0.8 of leg length
- hip height is CONTINUOUS across the cycle (this catches seams)
- the hips actually rise and fall
- the barrel points where the mouse is, to a fraction of a radian
- an arm is never longer than an arm
- a blocked pedestrian turns a few times a second, not sixty
- a climb never moves more than a few px PER FRAME (measure per frame, not per
fraction of the move — a duration-blind metric passes a seven-pixel hop)
The trap: "hips stay up", "never levitate" and "height is continuous" are
ALL perfectly satisfied by a dead-level line. A too-generous ankle roll once
cancelled the geometric dip exactly, the figure glided, and every assertion
stayed green. Assert the presence of motion, not only its absence of faults.
Rule 10 — vary it per step, or it reads as a machine
A gait computed from speed alone is exactly periodic, and exact periodicity is
what reads as robotic. The give-away is not that any one step looks wrong — it
is that every step looks identical.
Hash the variation on the STEP NUMBER, not a stream, so a replay reproduces it
and two characters at the same speed do not wobble in unison; interpolate
between this step's value and the next so nothing jumps at the plant.
What may vary and what may not: anything feeding back into where a foot is
PLANTED must not, or the plant moves between the swing that placed it and the
stance that holds it — foot slide, reintroduced through the back door. So leave
stride and stance alone and put the variation into lift, swing amplitude, lean
and the carriage of the head. Add a constant left/right asymmetry too: one leg
lifting a little higher and the pair a hair off antiphase is most of what
separates a person from a mechanism, and it costs one number.
Assert it: consecutive steps must differ (sampled during SWING — in stance the
foot is planted and the knee is correctly identical every step), the same walk
must repeat exactly, and the two legs must not be mirror images.
Also useful: contact sheets. One gait sampled across a full cycle, side by side.
Foot slide, a limping knee and a hitch at the loop point are obvious in a row of
stills and invisible in one.
Rule 9 — get an art critique from a vision model, repeatedly
You cannot see whether it looks like the character. Put a game frame beside a
reference frame in front of a vision model and ask for a ranked, quantitative
critique; implement; repeat. Five rounds found, among others:
- boots drawn DARKER than the background, so they read as holes
- shoulder span at half the reference's, which made the head look too big when
the head was correct
- a highlight brighter than the reference's brightest fabric AND brighter than
the background, so highlights read as objects stuck on
- the head outlined twice, nesting a black crescent inside its own silhouette
- the fist pinned in front of the body for every frame of the cycle — an
animation bug no assertion caught
- the identity feature (a tri-lens goggle array) rotated ninety degrees
Drawing with discs, from the same reviews
If limbs are runs of overlapping circles, the review has concrete answers:
- Constant radius, never interpolated. Equal discs give a union with two
straight parallel edges; an interpolated run is a cone, and a cone tapers at
both ends, which is what reads as soft.
- Offset a highlight to TANGENCY, not to the centre. Put its centreline
(limbR - hiR) off the axis so the discs touch the silhouette on the lit
side. The lit edge then coincides with the outline and you get one hard edge
free. Centred, you get two soft edges and none.
- Terminate runs at joints, never mid-limb: an end at a joint reads as a
seam, an end mid-limb reads as a smear.
- An even value ladder beats a big jump. A reference garment steps about
sixteen lightness at a time and never more than eighteen; ours jumped
fifty-five in one step and read as plastic. And anchor the ladder high enough
that the steps above the base are visible — the same ladder with the base too
low buries the modelling inside the figure's own darkness.
- Gear is the character. A plate carrier is three stacked constant-radius
runs; that plus shoulder caps, knee pads and a belt is four gear pieces and
the biggest recognition gain available.
Two reviewers, not one, and give them no context. An art director asked
about palette, value structure, composition and environment, and an animator
asked ONLY about the figures and how they hold things — in terms a programmer
can turn into a joint angle or an IK target ("the rear elbow should be below
the weapon line", "the head leads the hips by half a head"). Hand each of them
the game frame and the reference and nothing else: no explanation of what was
built, no defence of it, no list of known issues. The animator found the
arms-solved-before-the-lean ordering bug above, which no assertion caught and
which had survived a dozen screenshots.
Ask for measurements, not impressions. Expect rounds to contradict each other
as each reacts to the last overcorrection — converge, and let the geometry break
ties where it can.