Hi!
I think there is a issue with the phaser 3 collision handler and matter-js. When i connect a function
to the event "collisionstart" with:
this.matter.world.on("collisionstart", function(event, body_a, body_b) {
console.log("collision start, between", body_a, body_b);
});
I spect that the function was called on each body collision. But when multiple collisions occur, the function is called one time, with the two bodies that collides first and a list of collisions pairs in the event param.
I wrote a simple example to illustrate this: https://codepen.io/hugoruscitti/pen/oqwezM?editors=1111
The code simply shows a box that falls to collide to other two boxes simultaneously:

In the console you will see that collision handler its called only one time.
Dig in the Phaser Source code i think this line [1] omits the other simultaneous collisions, maybe that "if" can be changed with a foreach on event.pairs list?
Oh, i think this issue also is present on the other collisions events "collisionactive" and "collisionend".
I would be very willing to do a pullrequest if you want!!!
ah, and thanks for making Phaser3!!!
1 - https://github.com/photonstorm/phaser/blob/master/src/physics/matter-js/World.js#L196
This issue also occurs in my game, but I never thought about it deeply since my game objects are rarely collide within the same frame. I think you can totally make a PR for it.
@hugoruscitti - agree that it's a little confusing, but that implementation is intentional as far as I know. I stumbled across the same issue. Phaser is just passing along matter's internal "collisionStart" event and renaming it to "collisionstart" to match the rest of Phaser. bodyA and bodyB are added for convenience. You should loop over event.pairs.length in your collide handler code if you want to catch all the pairs that collided in that tick of the matter engine.
Maybe the discussion should be around removing bodyA and bodyB from the API since those are misleading at first glance. The times I've used matter, I've had more than 1x pair of colliders on many (or most?) frames.
This is how it's supposed to work (as Mike has explained, thanks) - I'm going to keep the bodyA/B arguments and just make sure the docs state they're the FIRST matching pair in the result set, but it's up to you to figure out the rest.
Most helpful comment
@hugoruscitti - agree that it's a little confusing, but that implementation is intentional as far as I know. I stumbled across the same issue. Phaser is just passing along matter's internal "collisionStart" event and renaming it to "collisionstart" to match the rest of Phaser.
bodyAandbodyBare added for convenience. You should loop overevent.pairs.lengthin your collide handler code if you want to catch all the pairs that collided in that tick of the matter engine.Maybe the discussion should be around removing
bodyAandbodyBfrom the API since those are misleading at first glance. The times I've used matter, I've had more than 1x pair of colliders on many (or most?) frames.