Skip to content

Don't scale compound sweep overlap queries by maximumT twice - #427

Open
bholcomb wants to merge 1 commit into
bepu:masterfrom
bholcomb:fix-compound-sweep-maximum-t
Open

bholcomb wants to merge 1 commit into
bepu:masterfrom
bholcomb:fix-compound-sweep-maximum-t

Conversation

@bholcomb

@bholcomb bholcomb commented Oct 24, 2026 •

Copy link
Copy Markdown

BoundingBoxHelpers.GetLocalBoundingBoxForSweep returns sweep as the displacement over the whole sweep, (velocityA.Linear - velocityB.Linear) * maximumT. ConvexCompoundSweepOverlapFinder and CompoundPairSweepOverlapFinder then pass that displacement to FindLocalOverlaps together with maximumT, and Compound, BigCompound and Mesh all build their query ray from sweep and run it to maximumT. So the child query only reaches velocity * maximumT².

With maximumT < 1, a sweep misses every child beyond that point. A sphere swept 0.8 units at a box 0.75 units away hits it when the box is a plain shape, but misses the same box as a compound child or a mesh. The same displacement split as velocity 0.8 and maximumT = 1 hits. CCD sweeps in NarrowPhase pass the timestep as maximumT, so they only looked velocity * dt² ahead. With maximumT > 1 the query just looked further than it had to.

I ran into it with a character controller sweeping a capsule a short distance against a large compound: sweeps shorter than 1 unit missed children well within their reach.

The fix passes 1 as the overlap query's maximum t in both finders, since the sweep is already the full displacement.

Minimal repro (a sphere swept 0.8 units at a three-box compound whose near face is 0.75 units away):

var pool = new BufferPool();
var simulation = Simulation.Create(pool, new DemoNarrowPhaseCallbacks(), new DemoPoseIntegratorCallbacks(), new SolveDescription(1, 1));
var box = simulation.Shapes.Add(new Box(1, 1, 0.1f));
pool.Take(3, out Buffer<CompoundChild> children);
for (int i = 0; i < 3; ++i)
    children[i] = new CompoundChild(new RigidPose(new Vector3(i - 1, 0, 0)), box);
simulation.Statics.Add(new StaticDescription(new Vector3(0, 0, -0.9f), simulation.Shapes.Add(new Compound(children))));
var handler = new NearestHitHandler { T = float.MaxValue }; //Keeps the smallest t from OnHit.
simulation.Sweep(new Sphere(0.1f), RigidPose.Identity, new BodyVelocity(new Vector3(0, 0, -1)), 0.8f, pool, ref handler);

Over Box, Compound, BigCompound and Mesh walls, for a sphere and for a compound holding the sphere (through the sweep task, as CCD does), before (29ed466):

velocity  maximumT  Box    Compound  BigCompound  Mesh
1         0.8       hit    MISS      MISS         MISS
0.8       1         hit    hit       hit          hit
60        1/60      hit    MISS      MISS         MISS

The compound holding the sphere also misses the plain box for the first and last rows. After, every case hits at 0.750.

Tested with the standalone repro above against master and with the fix, and with DemoTests/CompoundSweepTests.cs, which sweeps a sphere and a compound at each wall type with maximumT of 0.8, 1, 2 and 1/60. Both tests fail on master and pass with the fix. I ran them on Linux against BepuPhysics alone, since the Demos content build needs d3dcompiler there.

GetLocalBoundingBoxForSweep returns the sweep as the displacement over
maximumT (relative velocity * maximumT). The convex-compound and
compound-pair sweep overlap finders then passed that displacement to
FindLocalOverlaps along with maximumT again, so the child query ray only
reached velocity * maximumT^2. With maximumT < 1, a sweep missed every
Compound, BigCompound and Mesh child beyond that point: a sphere swept
0.8 units at a box 0.75 units away hit it alone but missed it as a
compound child. CCD sweeps pass the timestep as maximumT, so they only
looked velocity * dt^2 ahead. With maximumT > 1 the query looked further
than needed.

The overlap query now runs to t = 1 over the displacement.
@RossNordby

Copy link
Copy Markdown
Member

oops! thanks for the report! will try to get to this soon.

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.

2 participants