Skip to content

Use predicted velocities in the narrow phase to fix compound tunneling - #429

Open
Nigel-Bess wants to merge 1 commit into
bepu:masterfrom
Nigel-Bess:fix-compound-tunneling
Open

Nigel-Bess wants to merge 1 commit into
bepu:masterfrom
Nigel-Bess:fix-compound-tunneling

Conversation

@Nigel-Bess

Copy link
Copy Markdown

Fixes the bug reported in #390, with a repro in #388.

Problem

PredictBoundingBoxes integrates velocity up front to expand bounding boxes, but then throws the integrated velocity away. The broad phase finds the compound's overlap using the predicted velocity. The narrow phase's compound child overlap test then expands child bounds using the stored, pre-integration velocity. With a large dt * acceleration (the #388 repro uses dt = 0.12 with gravity of 9807 mm/s²), the child bounds never reach the floor, so no child pair is created and the compound falls through. An identical non-compound box is unaffected.

Fix

This is option 2 from your comment on #388:

  • PredictBoundingBoxes stores the integrated velocities in Bodies.PredictedVelocities.
  • NarrowPhase.HandleOverlap reads them through GetVelocityForCollisionDetection, so the CCD sweep and the compound/mesh child bounds tests use the same velocity as the broad phase.
  • The prediction is invalidated at the end of Simulation.CollisionDetection and whenever RemoveFromActiveSet reorders the active set. Bodies added after prediction fall back to their stored velocity.

The cost is one extra BodyVelocity write per active body during prediction, plus the buffer.

Testing

I ran a headless version of the #388 scene (compound vs. plain box, dt = 0.12, 30 steps) across 1 and 4 substeps, Discrete/Passive/Continuous, with and without a thread dispatcher.

Box final y Compound final y
Before 69.0 ≈ -65,500
After 69.0 69.0

All 12 configurations fail before the change and pass after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant