Skip to content

Commit

Permalink
fix collision events for sleeping pairs, closes #1077
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Nov 13, 2023
1 parent e9da32c commit 51f49ce
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/collision/Pairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ var Common = require('../core/Common');
if (pair.isActive) {
// pair exists and is active
collisionActive[collisionActiveIndex++] = pair;
} else {
// pair exists but was inactive, so a collision has just started again
collisionStart[collisionStartIndex++] = pair;
}

// update the pair
Expand All @@ -89,16 +86,21 @@ var Common = require('../core/Common');
for (i = 0; i < pairsListLength; i++) {
pair = pairsList[i];

if (pair.timeUpdated < timestamp) {
// pair is active if updated this timestep
if (pair.timeUpdated >= timestamp) {
// keep active pairs
pairsList[pairsListIndex++] = pair;
} else {
pairSetActive(pair, false, timestamp);
collisionEnd[collisionEndIndex++] = pair;

// remove inactive pairs
if (!pair.collision.bodyA.isSleeping && !pair.collision.bodyB.isSleeping) {
// keep inactive pairs if both bodies may be sleeping
if (pair.collision.bodyA.sleepCounter > 0 && pair.collision.bodyB.sleepCounter > 0) {
pairsList[pairsListIndex++] = pair;
} else {
// remove inactive pairs if either body awake
collisionEnd[collisionEndIndex++] = pair;
delete pairsTable[pair.id];
}
} else {
pairsList[pairsListIndex++] = pair;
}
}

Expand Down

0 comments on commit 51f49ce

Please sign in to comment.