kpded Posted October 8, 2018 Share Posted October 8, 2018 Hello! I'm trying to identify the place and normal vector of collision to launch a bunch of particles when two bodies collide in MatterJS. So following example on collision filtering https://labs.phaser.io/edit.html?src=src\physics\matterjs\collision event.js I have something like function create () { var blockA = this.matter.add.image(0, 300, 'block').setBounce(1).setFriction(0); var blockB = this.matter.add.image(600, 300, 'block').setStatic(true); blockA.setVelocityX(10); this.matter.world.on('collisionstart', function (event, bodyA, bodyB) { // launch particles here at collision point }); } But unfortunately 'collisionstart' event provides just bodies of two gameObject collided and no information on where the collision took place So is there any way to detect where did the collision happen and what was the normal direction? Or perhaps one can access MatterJS collision object directly, as far as I can see it contains this information? I'm using MatterJS because I need to collide non-convex polygons, so if you have any possible alternative in mind I would appreciate if you share it with me Link to comment Share on other sites More sharing options...
rich Posted October 8, 2018 Share Posted October 8, 2018 The 'event' passed to your callback is all of the Matter collision event data, untouched. Anything you can get via Matter normally, you can get from that event. Link to comment Share on other sites More sharing options...
kpded Posted October 9, 2018 Author Share Posted October 9, 2018 Thank you @rich Yeah this data doesn't contain any information on collision point But matterjs calculates it anyway in Engine.update(), just doesn't pass with event. It can be found here https://github.com/photonstorm/phaser/blob/c6faa7c8a7f1dac9a06a629458c0c05f4eaa6602/src/physics/matter-js/lib/core/Engine.js#L192 It feels like we need to pass collisions array along with the pairs. A collision from that collisions array contains 'normal' and 'supports' members, that are a normal vector of the collision and points (may be one or two) that describe a collision point Changing this directly in phaser.js file gives a result that looks decent at a glance (see gif attached) I do understand that this can't be a robust solution, so I'm trying to wrap my head around overwriting Phaser.Physics.Matter.Matter.Engine.update() method. With no luck so far: I can't understand how can I get to the scope of the original function So if anyone can advise me on a way to overwrite that function, it would be awesome Link to comment Share on other sites More sharing options...
rich Posted October 9, 2018 Share Posted October 9, 2018 This is something you should request on the matter repo. If they add it upstream, I can expose it downstream. kpded 1 Link to comment Share on other sites More sharing options...
kpded Posted October 19, 2018 Author Share Posted October 19, 2018 People at matter repo helped me to solve this issue without changing the source. The idea is that one can access all pairs of colliding objects through the array this.matter.world.engine.pairs.list at every update frame Every member of this array contains bodies of colliding objects and 'collision' object. The 'collision' object in turn contains that 'normal' and 'supports' properties, that I needed Link to comment Share on other sites More sharing options...
Recommended Posts