diff --git a/src/body/Composite.js b/src/body/Composite.js index b814d7d..7f3f01f 100644 --- a/src/body/Composite.js +++ b/src/body/Composite.js @@ -246,6 +246,10 @@ var Body = require('./Body'); var position = Common.indexOf(composite.bodies, body); if (position !== -1) { Composite.removeBodyAt(composite, position); + + // remove sleeping to allow pair removal + body.isSleeping = false; + body.sleepCounter = 0; } if (deep) { diff --git a/src/collision/Pairs.js b/src/collision/Pairs.js index 6d931ce..debd74b 100644 --- a/src/collision/Pairs.js +++ b/src/collision/Pairs.js @@ -45,6 +45,8 @@ var Common = require('../core/Common'); collisionEnd = pairs.collisionEnd, collisionActive = pairs.collisionActive, collision, + bodyA, + bodyB, pairIndex, pair, i; @@ -92,15 +94,24 @@ var Common = require('../core/Common'); for (i = 0; i < pairsListLength; i++) { pair = pairsList[i]; - - if (!pair.confirmedActive) { - Pair.setActive(pair, false, timestamp); - if (!pair.collision.bodyA.isSleeping && !pair.collision.bodyB.isSleeping) { - collisionEnd.push(pair); - removePairIndex.push(i); - } + // keep pair if it had a collision this update + if (pair.confirmedActive) { + continue; } + + bodyA = pair.collision.bodyA; + bodyB = pair.collision.bodyB; + + // keep pair if it is sleeping but not both static + if ((bodyA.isSleeping || bodyA.isStatic) && (bodyB.isSleeping || bodyB.isStatic) + && !(bodyA.isStatic && bodyB.isStatic)) { + continue; + } + + Pair.setActive(pair, false, timestamp); + collisionEnd.push(pair); + removePairIndex.push(i); } // remove inactive pairs