dussman Posted August 23, 2015 Share Posted August 23, 2015 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. Do you know a way to also flip the P2 body? Thanks in advance. Link to comment Share on other sites More sharing options...
icp Posted August 23, 2015 Share Posted August 23, 2015 scale.x apply the effect on texture only.You could create 2 JSON files for each position and load the position you need. Or you could create a ragdoll:http://schteppe.github.io/p2.js/demos/ragdoll.htmlThird option would be to edit the JSON data but that is more complicated. Link to comment Share on other sites More sharing options...
dussman Posted August 29, 2015 Author Share Posted August 29, 2015 Thanks ICP I've created two different files but I'm getting now another problem with the new physics polygon 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 More sharing options...
tips4design Posted August 29, 2015 Share Posted August 29, 2015 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) Link to comment Share on other sites More sharing options...
dussman Posted August 29, 2015 Author Share Posted August 29, 2015 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 More sharing options...
Recommended Posts