Jump to content

[P2] Sprite and shape don't have same center


titmael
 Share

Recommended Posts

Hi,

 

I use P2 and when I want to add a circle shape for collision to my sprite, they don't share the same center point and of course it mess up my game.

 

mini_2760682014043019h3004.png

 

Here is the code I use :

this.starsCollisionGroup = game.physics.p2.createCollisionGroup();this.bonusesCollisionGroup = game.physics.p2.createCollisionGroup();[...]this.bonusGroup = game.add.group();this.bonusGroup.createMultiple(5, 'bonus_meteor');this.bonusGroup.enableBody = true;this.bonusGroup.physicsBodyType = Phaser.Physics.P2JS;[...]​var bonus = this.bonusGroup.getFirstDead();game.physics.p2.enable(bonus, true);bonus.body.setCircle(22);bonus.body.setCollisionGroup(this.bonusesCollisionGroup);bonus.body.collides([this.meteor.collisionGroup]);bonus.body.velocity.y = -600 * this.speed;bonus.body.collideWorldBounds = false;bonus.checkWorldBounds = true;bonus.outOfBoundsKill = true;

I don't see anything to explain that behavior. Any idea ?

 

Thanks  ;)

Link to comment
Share on other sites

Tadaaaaaaaaaaaaaaaaa ! In fact the gap was from velocity applied to the body.

I just hacked my code to manually move the sprite in the update.

 

If you have anything to properly fix that would be nice, I prefer velocity to manual mouve.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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