Skip to content

Commit

Permalink
fix: CompositeCollider literal edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Dec 28, 2024
1 parent 1827afb commit ec34e7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/engine/Collision/Colliders/CollisionJumpTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ export const CollisionJumpTable = {
txA.apply(contact.info.localSide.begin).add(shapeA.offset),
txA.apply(contact.info.localSide.end).add(shapeA.offset)
);
worldPoint = txB.apply(localPoint);
worldPoint = txB.apply(localPoint).add(shapeB.offset);
} else {
side = new LineSegment(
txB.apply(contact.info.localSide.begin).add(shapeB.offset),
txB.apply(contact.info.localSide.end).add(shapeB.offset)
);
worldPoint = txA.apply(localPoint);
worldPoint = txA.apply(localPoint).add(shapeA.offset);
}

return side.distanceToPoint(worldPoint, true);
Expand Down
6 changes: 4 additions & 2 deletions src/engine/Collision/Solver/ContactConstraintPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ export class ContactConstraintPoint {
*/
update() {
const bodyA = this.contact.bodyA;
const colliderA = this.contact.colliderA;
const bodyB = this.contact.bodyB;
const colliderB = this.contact.colliderB;

if (bodyA && bodyB) {
const normal = this.contact.normal;
const tangent = this.contact.tangent;

this.aToContact = this.point.sub(bodyA.globalPos);
this.bToContact = this.point.sub(bodyB.globalPos);
this.aToContact = this.point.sub(colliderA.center);
this.bToContact = this.point.sub(colliderB.center);

const aToContactNormal = this.aToContact.cross(normal);
const bToContactNormal = this.bToContact.cross(normal);
Expand Down
6 changes: 4 additions & 2 deletions src/engine/Collision/Solver/RealisticSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ export class RealisticSolver implements CollisionSolver {

let pointIndex = 0;
const bodyA = contact.bodyA;
const colliderA = contact.colliderA;
const bodyB = contact.bodyB;
const colliderB = contact.colliderB;
if (bodyA && bodyB) {
for (let j = 0; j < contact.points.length; j++) {
const point = contact.points[j];
const normal = contact.normal;
const tangent = contact.tangent;

const aToContact = point.sub(bodyA.globalPos);
const bToContact = point.sub(bodyB.globalPos);
const aToContact = point.sub(colliderA.center);
const bToContact = point.sub(colliderB.center);

const aToContactNormal = aToContact.cross(normal);
const bToContactNormal = bToContact.cross(normal);
Expand Down

0 comments on commit ec34e7e

Please sign in to comment.