Skip to content

Commit 64fe1c8

Browse files
authored
bug fix - "moveWithCollisions" method parameter slideOnCollide==false now moves mesh to NEAR the collision point, instead of AT the collision point (#16587)
Issue - "moveWithCollisions" with the parameter slideOnCollide == false used to move the mesh up to the point of collision. Due to floating point inaccuracy, this sometimes meant just outside, and sometimes just inside penetration with the collided mesh. When just inside, subsequent calls to "moveWithCollisions" would snag on the mesh previously collided with. Solution - "moveWithCollisions" with the parameter slideOnCollide == false now moves the mesh NOT up to the point of collision, but up to a point just a small distance short of that collision. The small distance is based on "AbstractEngine.CollisionsEpsilon", the same distance considered "close" by other aspects of the collision system.
1 parent fa6b8e4 commit 64fe1c8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/dev/core/src/Collisions/collider.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,16 @@ export class Collider {
504504
// Handle straight movement up to collision
505505

506506
pos.addToRef(vel, this._destinationPoint);
507-
vel.scaleInPlace(this._nearestDistance / vel.length());
508-
509-
this._basePoint.addToRef(vel, pos);
510507

511508
if (!slideOnCollide) {
509+
// Move to one "close distance" less than the collision point to
510+
// prevent any collision penetration from floating point inaccuracy
511+
vel.scaleInPlace((this._nearestDistance - this._epsilon) / vel.length());
512+
this._basePoint.addToRef(vel, pos);
512513
return;
514+
} else {
515+
vel.scaleInPlace(this._nearestDistance / vel.length());
516+
this._basePoint.addToRef(vel, pos);
513517
}
514518

515519
// Handle slide movement past collision

0 commit comments

Comments
 (0)