i using phaser-matter-collision-plugin to phaser game.
https://github.com/mikewesthad/phaser-matter-collision-plugin .
How to set Collision Filter ? filter collision between two bodies, make the sprite body thought run thought another sprite body.
I try to set .setSensor(true)
to some sprite.body , but I think it is not the best way to solve the problem.
any idea??
`const player = this.matter.add.sprite(0, 0, "player");
const EmptyBody = this.matter.add.sprite(200, 0, "EmptyBody");
this.matterCollision.addOnCollideStart({
objectA: player,
objectB: EmptyBody,
callback: eventData => {
// anyidea to set two bodies through thier body ???
}
});`
Thank you very much??
It may help to assign a new collision category when the pointerdown function is called. Something like:
cat1= this.matter.world.nextCategory();
cat2= this.matter.world.nextCategory();
platform = this.matter.add.rectangle(100, 46, 40, 10, {
isStatic: true,
});
ball = this.matter.add.circle(100, 8, 6, {
isStatic: true
});
platform.setCollisionCategory(cat1);
ball.setCollisionCategory(cat2);
ball.setCollidesWith(cat2);
this.input.on("pointerdown", function() {
ball.setStatic(false);
…
This might help. Set your categories outside of the collision function, and then change the categories inside the function. You may not want to add a collision filter to the player though. Just provide a category for the EmptyBody, and then force it to only collide with its own category when it collides with the player.
Thanks you very much
Your code works fine for me, thanks again, have a nice day