Jump to content

P2 Physics - Suppress collision between two specific sprites


roscminni
 Share

Recommended Posts

Hi,

 

I'm just getting to grips with the P2 physics system. I am trying to get two boat sprites to race each other, but as they both have bodies they just collide. I would like them to collide with the sea sprite only. I have tried to use collisionGroups, but I don't really understand how they work. The code below is my latest attempt to do this:

 

this.game.physics.p2.enable([this.boat1,this.boat2, this.sea], false);var demoGroup = this.game.physics.p2.createCollisionGroup();this.sea.body.setCollisionGroup(demoGroup);this.jetski.body.collides(demoGroup);this.jetskiB.body.collides(demoGroup);

I can't help but feel there must be a really simple solution to this - but I can't find it.

 

Any help appreciated,

 

Link to comment
Share on other sites

With collisiongroups, you have to give the jetskis a different group, and then collide the jetskis against the sea, and the sea against the jetski group. 

 

this.game.physics.p2.enable([this.jetski,this.jerskiB, this.sea], false);var seaGroup = this.game.physics.p2.createCollisionGroup();var jetskiGroup = this.game.physics.p2.createCollisionGroup(); this.sea.body.setCollisionGroup(seaGroup);this.jetski.body.setCollisionGroup(jetskiGroup);this.jetskiB.body.setCollisionGroup(jetskiGroup); this.jetski.body.collides(seaGroup);this.jetskiB.body.collides(seaGroup);this.sea.body.collides(jetskiGroup);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...