Skip to content
Sleeping & Stability
step 1/5

Reading — step 1 of 5

Read

~2 min readProduction

Sleeping & Stability

In a stack of 100 boxes, only the top one moves typically. The rest can SLEEP.

Sleep heuristic:

  • Body's velocity below threshold for N consecutive frames → sleep.
  • Skip simulation for sleeping bodies.
  • Wake on contact / impulse from another body.
python

Dramatic perf win for static-heavy scenes (rooms full of boxes).

Numerical stability:

  • Tiny velocities accumulate over time (Euler error).
  • After many frames, motion deviates from physical reality.
  • Verlet is more stable.
  • Substepping: run 2-4 sub-steps per frame for stiff systems.

Stiff constraints:

  • High spring constants → small dt needed → instability.
  • Implicit integration: Verlet, position-based dynamics.
  • Or: lower constants + iterations.

Stacking stability:

  • N stacked boxes: tower of impulses.
  • Iterative solver needs O(N) iterations per frame to fully stabilize.
  • Without enough: jitter or sinking.

Solutions:

  • More iterations (8-30 typical).
  • Warm starting: reuse last frame's impulse as initial guess.
  • Position-based: solve at position level, not velocity.
  • Specialized stack stabilization.

Tunneling:

  • Fast-moving body passes through thin object in one timestep.
  • Common with bullets / fast platforms.

Solutions:

  • Smaller timestep.
  • Continuous collision detection (CCD): swept volumes.
  • Conservative advancement: cast bodies along velocity, find first hit.

Box2D's CCD:

  • For "bullet" objects only (flagged).
  • Solver does extra check.
  • Small perf cost.

Determinism:

  • Same input → same output.
  • Critical for networked games.
  • Float order-of-ops matters: parallel = non-deterministic.
  • Solutions: fixed point math, or carefully-ordered float ops.

Modern engines balance: speed, accuracy, stability, feature set.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…