Balance
The balance model behind a stagger: a small, deterministic simulation in the spirit of NaturalMotion's Euphoria (the ragdoll behaviour in GTA IV / V and Red Dead). It does not know about parts or joints; it turns "you were shoved this hard in this direction" into a stream of numbers the Controller turns into steps, leaning and a decision.
The character has a lurch (horizontal velocity they are being carried by) and a balance from 0 to 1. Balance drains while they are lurching. At irregular intervals they take a catch-up step: a clean step kills part of the lurch and buys some balance back, a stutter is a half step that buys less and comes sooner, and a misstep kicks them sideways and costs balance. When the lurch has died down with balance to spare they have recovered; when balance hits zero they fall.
Everything random comes from a Random seeded by the stagger, so the server and the
simulating client agree on what happens without talking.
Types
Outcome
type Outcome = "Staggering" | "Recovered" | "Fell"What Balance:Step returns.
Leg
type Leg = "Left" | "Right"Functions
new
Balance.new(intensity: number,--
1 is the preset as tuned; 0.5 half a shove, 2 a big hit.
seed: number--
Seed for the model's Random.
) → BalanceCreates a balance model.
Disturb
Balance:Disturb(amount: number,--
Balance to remove, 0 to 1.
) → ()
Knocks the model again without restarting it: adds lurch in direction (or the current
direction) and takes amount off the balance. The controller feeds bumps into this; you
can too.
Step
Balance:Step(dt: number,catch: number?--
0 to 1: how much the player is running the stumble out (walk input lined up with the lurch). Earns balance back and bleeds speed.
) → Outcome--
"Staggering" while undecided, then "Recovered" or "Fell" once and for all.
Advances the model by dt seconds. Call it every frame on the simulating side.
Lean
Balance:Lean() → numberHow far the torso should lean into the lurch right now, in radians.
ArmRaise
Balance:ArmRaise() → numberHow far the arms should be out, 0 to 1.