boolean Posted May 9, 2015 Share Posted May 9, 2015 Hi there I'm learning up on how P2 collision groups work and I have a question. It seems that if I have two collision groups, one for the player and one for platforms, to get the two to interact I have to write:this.ground.body.collides(playerCollisionGroup);this.player.body.collides(groundCollisionGroup);If I just use one of those statements the collisions don't work, I have to use both. This seems a little strange - if ground is set to collide with player, why do I also have to set the player to collide with ground? It seems a little redundant. Is there a reason it has to be bound twice? Rich is a heck of a lot smarter than me so I assume I'm just missing a very good reason for this Cheers! Link to comment Share on other sites More sharing options...
icp Posted May 10, 2015 Share Posted May 10, 2015 Sprite.body.collides([FirstCollisionGroup, SecondCollisionGroup, ThirdCollisionGroup]);Use an array with alll the collision groups for each sprite and also be sure that you set each sprite a Collision Group :Sprite.body.setCollisionGroup(FirstCollisionGroup); Link to comment Share on other sites More sharing options...
valueerror Posted May 10, 2015 Share Posted May 10, 2015 @icp: this doesn't exactly answer the question.. i think boolean already figured out how to make them collide but is wondering why i have to set bodyA to collide with bodyB and vice versa.. if A collides with B the logical outcome would be that B also collides with A - so why the redundance.. IMHO the best approach would be to set it independently from the bodies like. phaser.pyhysics.p2.setCollisions(ArrayA, ArrayB); //pseudocode !! all collisiongroups in arrayA should collide with all collisiongroups in arrayB) Link to comment Share on other sites More sharing options...
boolean Posted May 10, 2015 Author Share Posted May 10, 2015 @valueerror: Thanks, yep that's correct - I was more curious about the 'why' rather than the 'how'. If there is a reason that you need to double-bind collisions, it would be good to know what case that solves. I like your pseudo code and it works a lot closer to how the collisions are setup in Arcade physics. I wonder what the reason for that not already existing is. Curious! Link to comment Share on other sites More sharing options...
drhayes Posted May 11, 2015 Share Posted May 11, 2015 I can't speak for Rich, but I can make up an example. Maybe enemies affect the player when colliding (e.g. hot death) while the player colliding with enemies should do nothing. The asymmetry is mirrored in the collision call. Link to comment Share on other sites More sharing options...
Recommended Posts