📚 Encyclopedia

Games & Graphics · updated 2026-10-13

Collision tunneling (fast objects passing through walls)

collisionphysicsccdraycastswept-aabbflame

Tunneling happens when an object moves farther in one frame than the thickness of what it should hit, so a discrete overlap test never sees the contact. It exists in every 2D engine with discrete collision; it is not a framework bug (Justin once asked about rewriting Run in vanilla JS over it; switching engines would not have helped).

Approaches, in order of preference

  1. Fixed-timestep substepping: split the frame into fixed steps (1/120 s) and run integrate + detect + resolve in each. Erin Catto (Box2D) moved Box2D v3 to substeps as the primary method, calling it simpler and more robust than continuous collision. Requires owning the collision pass (Fixed-timestep game loop for browser games).
  2. Swept AABB: Minkowski-expand each static box by the mover's half-extents and do a ray-vs-box test along the velocity to get the exact time of impact (Metanet's N tutorial covers this for tile platformers).
  3. Raycast from previous to current position: cheap safety net, ideal for projectiles and lasers.

What happened in Run (Flame), chronologically

  1. Manual swept test iterating every platform each frame: worked, but O(n) per frame caused frame spikes and audio stutter.
  2. dt clamping (20 ms cap): physics felt floaty at low fps. Reverted.
  3. Substepping inside update(): does not work in Flame, because Flame's collision detection runs once after all updates, not between substeps; gravity also compounded. Reverted.
  4. Flame raycast (kept): after the move, game.collisionDetection.raycast() (QuadTree backed, roughly O(log n)) from the previous to the current position, filtered to solid platforms and turret bodies; on hit, snap position, zero velocity, register the contact. Only runs when displacement exceeds 14 px on an axis.

Later fixes to the raycast rescue (2026-07 improvement cycles): - Use one-frame "pending" flags rather than adding to the contact set directly; a bare contact removal burned the buffered ground jump and the double jump. - Make the one-way-platform filter direction-aware and admit one-way landings based on the previous position (pure predicates, unit-tested).

Don'ts

References

See also

Linked from

Sources: run memory (research-collision-audio.md, session-v053-v057.md, improvement-cycles.md)