Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

P2 Static body collision issue


Iszard
 Share

Recommended Posts

Heyo,

I'm currently building a side scrolling space shooter and desired to have pixel perfect collision detection to allow a better experience dodging bullets and correctly colliding with enemies. To do this I used the P2 engine with loadPolygon functionality. However I have run into a problem were I can't stop the physics (velocity) from transferring from my bullet to my enemy and/or rotating either of the objects which becomes more noticeable when re-using pools of objects (although the objects in question retain a angle/rotation of 0).

Any solutions I have come across to make the bullet and enemy static has end up with a no collision detection scenario.

-Once you set two different body's to static = true they no longer fire collision events.
-If body's kinematic = true then the same happens with no fire collision events.

I've reviewed the examples page, however the kinematic and/or static demo's only work if your not kill/reset 'ing the objects. Once that happens there is no collision or in my case the player is auto firing currently so it's bullets are kill/reset before enemies are even placed on the screen.

Much googling has come across postings of similar issues in the 2014 and 2015 and I was wondering if there is any resolution to this problem yet? Having two static/kinematic P2 bodies collide without transferring any velocity to each other, just need a collusion detection event for firing custom logic (kill bullet, damage enemy);

 

Snippet of working example prier to static/kinematic setting: (similar code is used for enemies / player and enemy bullets and collision work 100% until static/kinematic is turned on to all parties)

this.game.physics.p2.enable([this.player], true);

this.player.body.clearShapes();
this.player.body.loadPolygon('enemy_physics', 'player');
// this.player.body.static = true;
// this.player.body.kinematic = true;

this.player.body.setCollisionGroup(this.playerCollisionGroup);
this.player.body.collides([this.enemyBulletsCollisionGroup, this.enemiesCollisionGroup], this.killPlayer, this);

Link to comment
Share on other sites

I've gone with the solution of setting the enemies as static = true while leaving the bullets as none static bodies. Upon collision detection I set:

    bullet.angularVelocity = 0;
    bullet.rotation = 0;

And the bullets no longer act undesirably when replaced from pool.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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