hello i made a simple slot machine game with sensor on when an object hit the bottom area. but it seems there are case where sensor is not triggered properly.
below are the code i use to set up the sensor area
this.matter.world.on('collisionstart', (event)=> {
for (const pair of event.pairs) {
const bodyA = pair.bodyA;
const bodyB = pair.bodyB;
console.log(pair);
if (!bodyA.isSensor && !bodyB.isSensor) return;
const sensor = bodyA.isSensor ? bodyA : bodyB;
console.log(`sensor ${sensor.label} is hit`);
this.goal();
}
});
i’m having hard time debugging these case without any clear reproduction process.
Does ‘collisionStart’ always trigger when you don’t use sensors?
If so, maybe you could handle it yourself by pair.isActive = false or something like that.
Or you could check ‘collisionActive’, and if you never received ‘collisionStart’ for that pair, you know you missed it.
yes it does. it prints every pair. but in the case it doesn’t trigger the corellated pair doesn’t print. i am thinking about using set 60hz if that even matter.
trying collision active seems to be more reliable. but for some reason the back of my head says it just one way of another hack. since i’ll be adding flag on stuff.