Skip to content

Commit 296059c

Browse files
committed
skip presolve when impulse 0
1 parent ccbb98b commit 296059c

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

src/collision/Resolver.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,26 @@ var Resolver = {};
186186
contactVertex = contact.vertex;
187187
normalImpulse = contact.normalImpulse;
188188
tangentImpulse = contact.tangentImpulse;
189-
190-
// total impulse from contact
191-
impulse.x = (normal.x * normalImpulse) + (tangent.x * tangentImpulse);
192-
impulse.y = (normal.y * normalImpulse) + (tangent.y * tangentImpulse);
193-
194-
// apply impulse from contact
195-
if (!(bodyA.isStatic || bodyA.isSleeping)) {
196-
offset = Vector.sub(contactVertex, bodyA.position, tempA);
197-
bodyA.positionPrev.x += impulse.x * bodyA.inverseMass;
198-
bodyA.positionPrev.y += impulse.y * bodyA.inverseMass;
199-
bodyA.anglePrev += Vector.cross(offset, impulse) * bodyA.inverseInertia;
200-
}
201189

202-
if (!(bodyB.isStatic || bodyB.isSleeping)) {
203-
offset = Vector.sub(contactVertex, bodyB.position, tempA);
204-
bodyB.positionPrev.x -= impulse.x * bodyB.inverseMass;
205-
bodyB.positionPrev.y -= impulse.y * bodyB.inverseMass;
206-
bodyB.anglePrev -= Vector.cross(offset, impulse) * bodyB.inverseInertia;
190+
if (normalImpulse !== 0 || tangentImpulse !== 0) {
191+
// total impulse from contact
192+
impulse.x = (normal.x * normalImpulse) + (tangent.x * tangentImpulse);
193+
impulse.y = (normal.y * normalImpulse) + (tangent.y * tangentImpulse);
194+
195+
// apply impulse from contact
196+
if (!(bodyA.isStatic || bodyA.isSleeping)) {
197+
offset = Vector.sub(contactVertex, bodyA.position, tempA);
198+
bodyA.positionPrev.x += impulse.x * bodyA.inverseMass;
199+
bodyA.positionPrev.y += impulse.y * bodyA.inverseMass;
200+
bodyA.anglePrev += Vector.cross(offset, impulse) * bodyA.inverseInertia;
201+
}
202+
203+
if (!(bodyB.isStatic || bodyB.isSleeping)) {
204+
offset = Vector.sub(contactVertex, bodyB.position, tempA);
205+
bodyB.positionPrev.x -= impulse.x * bodyB.inverseMass;
206+
bodyB.positionPrev.y -= impulse.y * bodyB.inverseMass;
207+
bodyB.anglePrev -= Vector.cross(offset, impulse) * bodyB.inverseInertia;
208+
}
207209
}
208210
}
209211
}

0 commit comments

Comments
 (0)