Four wheel contacts are sampled from a procedural terrain height field h(x,z). Fitting a plane through those four contact heights gives the chassis's own pitch (front-rear tilt) and roll (left-right tilt) — what a rigidly mounted stretcher would feel:
pitch = atan2(h_front - h_rear, wheelbase)
roll = atan2(h_left - h_right, track_width)
The stretcher rides on four independent vertical struts at the chassis corners. With leveling ON, each strut's target length cancels its own corner's share of the chassis tilt, so the four strut tops always sit on a world-level plane at ride height h₀:
target_i = h0 + dx_i·sin(pitch) + dz_i·sin(roll)
actual_i += (target_i - actual_i) · (1 - e^(-dt·k_response))
k_response falls as carried load grows (heavier stretcher = slower hydraulics), so heavier loads show more transient sway before the platform settles level. With leveling OFF, every strut holds a fixed length h₀ — the stretcher is rigidly bolted on and tips exactly as much as the ground does.
Note on the source engine: the 3D version of this simulator this page is built from pairs the roll term with the wrong corner offset in its strut-length formula (a sign/axis mismatch verified numerically: at a 15° test tilt its formula leaves a residual corner-height spread of over a metre instead of leveling). Its on-screen leveling only looks correct because a second, independent, hardcoded rotation quietly overrides the broken strut math. This 2D engine uses the corrected pairing above (dx with pitch, dz with roll, both added), verified to reduce that same 15° test case to a residual under 3 cm — so the “Platform pitch/roll” readouts here are the strut geometry's actual, honestly computed output, not a fixed fudge factor.
The stability margin approximates tip-over risk from the classic zero-moment-point idea: it shrinks as roll grows and as the load's centre of mass sits higher and heavier relative to the track width.
Drag the top-down map to pan the view; the pitch and roll panels are the front-rear and left-right cross-sections through the vehicle at that instant.