In a sequential-impulse solver, why do accumulated-impulse clamping and warm starting decide whether a tall stack of crates rests or jitters and sinks?
answer
- iterative, not exact
- load relayed contact by contact
- clamp the total impulse
- reuse last step's impulses
basics
~20 sAn iterative sequential-impulse solver relays a stack's weight contact by contact and converges slowly. Clamping the accumulated impulse lets later iterations undo overshoot; warm starting from last step's impulses begins near the answer, so a few iterations suffice.
solid answer
~50 sSequential impulses is projected Gauss-Seidel: the solver sweeps over the contacts a handful of times, and each contact computes the impulse that fixes its own relative velocity from the bodies' current velocities and applies it at once. Information moves only through shared bodies, so the top crate's weight reaches the floor contact over several sweeps, and heavy-on-light mass ratios slow it further; stopping early leaves downward velocity, which shows as sinking, and its correction shows as jitter. **Accumulated clamping** keeps each contact's total impulse non-negative while letting an increment be negative, so overshoot from early sweeps is taken back; friction is clamped to `mu` times the accumulated normal impulse. **Warm starting** caches each persistent contact's impulses and applies them at the start of the next step; a resting stack's impulses barely change, so the solver starts almost converged.
code
pseudocode · 21 lines// warm start: apply last step's impulses to persistent contacts
for each contact c:
applyImpulse(c, c.normalImpulse * c.n + c.tangentImpulse * c.t)
repeat iterationCount times:
for each contact c:
// friction, bounded by the accumulated normal impulse
// (a 3D solver repeats this for a second tangent direction)
vRel = relativeVelocity(c)
delta = -dot(vRel, c.t) * c.tangentMass
maxF = c.friction * c.normalImpulse
old = c.tangentImpulse
c.tangentImpulse = clamp(old + delta, -maxF, maxF)
applyImpulse(c, (c.tangentImpulse - old) * c.t)
// normal: drive the normal velocity to the target c.bias
vRel = relativeVelocity(c)
delta = (c.bias - dot(vRel, c.n)) * c.normalMass
old = c.normalImpulse
c.normalImpulse = max(old + delta, 0) // clamp the total
applyImpulse(c, (c.normalImpulse - old) * c.n)go deeper
Recall that a stack is solved by sweeping over all contacts several times, and that remembering last step's impulses helps a resting stack stay still.
Explain the sequential-impulse loop, why each impulse is applied immediately, and why the total impulse rather than each increment is clamped to be non-negative.
Diagnose a jittering, sinking stack from first principles: slow load relay, mass ratios, per-increment clamping, missing or stale warm starting, and unstable contact points.
Weigh iterative accuracy against cost across a whole game: where stable stacking truly matters, where approximate resting is fine, and what a parallel Jacobi variant would cost in convergence.
## Many contacts, one answer A single isolated contact can be solved in closed form. A **stack of crates** cannot: every crate touches the one below and the one above, the floor touches the bottom crate, and each contact's correct impulse depends on all the others. Mathematically this is a **linear complementarity problem**: for each contact the normal impulse must be non-negative, the separating velocity must be non-negative, and at least one of the two must be zero (a contact either pushes or separates, never both). Games almost never solve that system exactly. They use an iterative method known as **sequential impulses**, which is **projected Gauss-Seidel (PGS)** applied to the velocity-level contact problem. ## The sequential-impulse loop Each physics step runs roughly like this: 1. Integrate external forces such as gravity into the velocities. 2. **Warm start**: apply each contact's impulse remembered from the previous step. 3. Repeat a handful of times: visit every contact in turn, compute the impulse that would fix its own relative velocity given the bodies' **current** velocities, clamp it, and apply it at once. 4. Integrate positions from the corrected velocities. Applying each impulse immediately, so that the next contact already sees the change, is what makes it Gauss-Seidel rather than Jacobi. The clamping is the "projected" part. ## Why a stack converges slowly Each contact only sees the velocities of its two bodies. The weight of the top crate reaches the floor contact only by being relayed through every contact in between: - how far a correction travels in one sweep depends on the order the contacts are visited; in an unfavourable order it moves one contact per sweep; - **mass ratios** make it worse: a heavy crate on a light one swings the light one's velocity wildly, and the relay oscillates; - with only a few iterations the solve stops before the bottom contacts push hard enough, so the stack keeps a little downward velocity every step. That residual is the **slow sinking**. Whatever corrects the resulting overlap then pushes back, and the alternation between sinking and correction is the **jitter**. ## Clamp the total, not the increment A contact may only push, so its **total** impulse over the step must stay non-negative. The tempting implementation clamps each increment to be non-negative, and it is wrong. Suppose after the first sweep a contact has pushed with 5 units, but once its neighbours are solved the consistent total is 3: | scheme | increment computed | applied | total | |---|---|---|---| | clamp each increment to `>= 0` | -2 | 0 | 5, the overshoot is stuck | | clamp the accumulated impulse | -2 | -2 | 3, the overshoot is undone | With **accumulated-impulse clamping** the solver keeps `acc`, computes `newAcc = max(acc + delta, 0)` and applies `newAcc - acc`. Later iterations can take back what earlier ones overpushed, as long as the total stays a push. Friction is clamped the same way, against the **accumulated** normal impulse: `|accTangent| <= mu * accNormal`. ## Warm starting In a resting stack the contact impulses barely change from one step to the next: each crate still carries the same weight. **Warm starting** exploits that coherence: - store each contact's accumulated normal and friction impulses at the end of the step; - match contacts across steps through the persistent contact identifiers the collision stage provides; - apply the stored impulses before the first iteration, so the solver starts almost at the answer and a few iterations only refine it; - drop the stored impulse of any contact that did not persist, because a stale impulse applied to a new contact makes bodies pop. Without warm starting, the stack's weight has to be rebuilt from zero every step, and for a tall stack a handful of iterations often does not get there. ## What a stable stack needs - Accumulated clamping, so iterations converge instead of locking in overshoot. - Warm starting, so convergence carries across steps. - Stable contact points from the collision stage, so warm starting has something to match. - A position correction that removes the leftover overlap without adding energy. Remove any one of these and a tall stack shows it first.
- Why is applying each impulse immediately better for stacking than computing all impulses first and applying them together?Applying at once is Gauss-Seidel: the next contact sees the updated velocities, so corrections propagate within a sweep. Computing all first is Jacobi: every contact works from stale velocities, neighbours fight over the same error and convergence is slower and can overshoot unless the impulses are scaled down. Jacobi parallelises easily, which is its appeal.
- What goes wrong if warm starting reuses impulses for contacts that did not persist?A stored impulse belongs to a specific contact feature. Applied to a new contact with a different position or normal, it pushes in the wrong place or direction, injecting energy, so bodies pop or spin. Only contacts matched through persistent identifiers should be warm started; new contacts start from zero.
- Why does a heavy crate on top of a light one make the stack harder to solve?The light crate's velocity reacts strongly to every impulse, so each contact it shares keeps over-correcting the other. The heavy crate's weight must pass through that oscillating middle body, and Gauss-Seidel needs many more sweeps to settle. Large mass ratios are a classic cause of a stack that never rests.
A line of people passing a heavy message by whispering only to their neighbours: one pass gets it partway down the line, and starting each round with what everyone heard last round is far faster than starting from silence.
- Clamping each incremental impulse to be non-negative is the same as clamping the total.
- An iterative contact solver finds the exact solution in a single sweep.
- Warm starting means running extra iterations on the first frame.
- Friction should be clamped against the body's weight rather than the accumulated normal impulse.
- Sinking stacks are always fixed by turning up restitution.