0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-21 17:14:38 -05:00

fix collision events for sleeping pairs, closes #1077

This commit is contained in:
liabru 2023-11-13 23:32:39 +00:00
parent e9da32c886
commit 51f49ce9d3

View file

@ -64,9 +64,6 @@ var Common = require('../core/Common');
if (pair.isActive) { if (pair.isActive) {
// pair exists and is active // pair exists and is active
collisionActive[collisionActiveIndex++] = pair; collisionActive[collisionActiveIndex++] = pair;
} else {
// pair exists but was inactive, so a collision has just started again
collisionStart[collisionStartIndex++] = pair;
} }
// update the pair // update the pair
@ -89,16 +86,21 @@ var Common = require('../core/Common');
for (i = 0; i < pairsListLength; i++) { for (i = 0; i < pairsListLength; i++) {
pair = pairsList[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); pairSetActive(pair, false, timestamp);
collisionEnd[collisionEndIndex++] = pair;
// remove inactive pairs // keep inactive pairs if both bodies may be sleeping
if (!pair.collision.bodyA.isSleeping && !pair.collision.bodyB.isSleeping) { 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]; delete pairsTable[pair.id];
} }
} else {
pairsList[pairsListIndex++] = pair;
} }
} }