roscminni Posted August 5, 2014 Share Posted August 5, 2014 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 More sharing options...
wayfinder Posted August 5, 2014 Share Posted August 5, 2014 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 More sharing options...
roscminni Posted August 6, 2014 Author Share Posted August 6, 2014 Thanks, that appears to work - I think the main mistake I made was not loading the polygons after defining the collision groups. Link to comment Share on other sites More sharing options...
Recommended Posts