Jump to content

P2 collisionGroup no collisions


titmael
 Share

Recommended Posts

Hi,

 

With P2, I have in my game a meteor and stars. I have 2 groups : meteorCollisionGroup and starsCollisionGroup.

 

When I create my meteor I do :

this.sprite.body.collides(this.starsCollisionGroup, this.hitObstacle, this);

When I pop a star, I do 

star.body.setCollisionGroup(this.starsCollisionGroup);star.body.collides([this.meteor.collisionGroup]);

When my meteor hit a star, I scale it down (and when it's a bonus (another group) I scale it up) :

this.sprite.scale.x = this.sprite.scale.x * 0.9;this.sprite.scale.y = this.sprite.scale.y * 0.9;this.sprite.body.setCollisionGroup(this.collisionGroup);

Then my meteor sometime overlap a star without hitting it ... and I have no clue why I have this behavior. When I activate debug on bodies, nothing's wrong.

 

Looks like stars overlaped have already poped when scaling down my meteor. But lots of already poped stars do hit my meteor.

 

If you have any idea, you are welcome  :P

Link to comment
Share on other sites

I updated my first post with :

star.body.collides([this.meteor.collisionGroup]);

I already do it when creating the star, so you mean I have to re-do it when scalling down my meteor ?

Link to comment
Share on other sites

I think its like this. If you just scale the sprite, then you wont have a problem. But, if you change the P2 physics body size, then you have to reset setCollisionGroup(entityCollisiongroup) and collides(entityCollisiongroup) after a resize. 

I do not have to set callback on collsions between collisiongroups again though. Only reset the collisiongroup and that I want it to collide with itself.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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