Jump to content

[P2] CollisionGroups and body.collides method


pandavigoureux29
 Share

Recommended Posts

Hi all, 

 

I have some issues with CollisionGroups ( I used to use them for ImpactEvents and am starting to wonder if there are not made just for that)

 

I'll try to make it short and clear :

 

Let's take two collision groups :

var playerGroup = game.physics.p2.createCollisionGroup();var groundGroup = game.physics.p2.createCollisionGroup();

Now let's take two sprites (assume they are created and physics is enabled) and set their collision groups:

player.body.setCollisionGroup(playerGroup);ground.body.setCollisionGroup(groundGroup);

With that if I want to enable collisions between these two sprites, I have to do this :

player.body.collides(groundGroup);ground.body.collides(playerGroup);

So here is the issue : if I put just one of these line, nothing happens.

Isn't it enough to tell one body or the other to collide? It seems redundant to me.

 

If that's the way it is, I'll deal with it, but I want to be sure I'm not making any mistake here

 

Thanks

Link to comment
Share on other sites

I totally see the point of collision mask ,  but, in my example, I don't see how the player can collide with ground without ground colliding with the player.

It just seems to me I am writing two lines that do the same thing.

my thoughts exactly... but it seems to be that way so i deal with it... you could spare a lot of lines if you dont use this at all and instead work with onBeginContact()

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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