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

P2 physics flip body orientation


dussman
 Share

Recommended Posts

HI, I'm making a game with P2 Physic and I'm struggling with a little problem.

 

I've created a polygon shape with PhysicsEditor and attached it to a sprite. The problem comes when I move my sprite to the left and change my orientation with:

 player.scale.x =  - 1;

The sprite flips but the shape stays the same.

normal.png    image.png

 

Do you know a way to also flip the P2 body?

 

Thanks in advance.

Link to comment
Share on other sites

Thanks ICP I've created two different files but I'm getting now another problem with the new physics polygon

 

upload.png

 

 

for some reason when I change the shape it moves the new body to the right. Here is the code of the update method:

player.update = function () {            player.body.velocity.x = 0; //default speed - stationary            if ( game.input.keyboard.isDown( controls.left ) ) {                player.scale.x = -1;                player.body.moveLeft( sideSpeed );                player.body.clearShapes();                player.body.loadPolygon('physicsLeftData', 'player');                setBody();            }            else if ( game.input.keyboard.isDown( controls.right ) ) {                player.scale.x = 1;                player.body.clearShapes();                player.body.loadPolygon('physicsData', 'player');                console.log( player.body );                player.body.moveRight( sideSpeed );                setBody()            }            if ( game.input.keyboard.isDown( controls.jump ) && checkIfCanJump() && this.game.time.now > player.jumpTimer ) {                player.body.moveUp( jumpSpeed ) ;                player.jumpTimer = this.game.time.now + 0;            }        };function setBody() {            player.body.fixedRotation = true;            player.body.setCollisionGroup( collisionGroup );            player.body.setMaterial( material );            player.body.collideWorldBounds = true;            player.body.mass = 4; }

Does anybody knows why this happens?

Link to comment
Share on other sites

Is the body actually there? (have you tried colliding it with something to check?) Because I also see the body being offset from the sprite when the sprite is in a layer that I moved (may be a body debug bug)

 

Yeah the body is where you see the polygon, I have a ball bouncing around and it collides against the polygon shape

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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