Gamble202 Posted March 19, 2015 Share Posted March 19, 2015 Hello. I would like to make a seesaw with the P2 physics, but have some weird behavior.(excuse my english, i just start to learn) so i made this:var game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameDiv', { preload: preload, create: create, update: update, render: render });function preload() { game.load.image('plate', 'img/lock_plat.png'); game.load.image('bowling', 'img/bowling.png');}function create() { game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.gravity.y = 250; plate = game.add.sprite(400,428, 'plate'); bowl = game.add.sprite(500, 350, 'bowling'); game.physics.enable( [plate,bowl], Phaser.Physics.P2JS); bowl.body.debug = true; bowl.collideWorldBounds = true; bowl.body.setCircle(20,0,0,0); bowl.body.mass = 100; plate.body.debug = true; plate.body.mass = 10; ballMateria = game.physics.p2.createMaterial('bowlMateria', bowl.body); basculeMateria = game.physics.p2.createMaterial('basculeMateria', plate.body); genericCM = game.physics.p2.createContactMaterial(ballMateria, basculeMateria); genericCM.friction = 1; genericCM.stiffness = 1e10; genericCM.restitution = 0; genericCM.relaxation = 0; }function update() { if(plate.body.x != 400){ plate.body.x = 400; } if ( plate.body.y != 428){ plate.body.y = 428; } if (plate.body.rotation > 0.2){ plate.body.rotation = 0.2; } console.log(plate.body.x+' / '+plate.body.y+' - '+ plate.body.rotation);}function render() {}The plate is a rectangular sprite and the bowl a circle. And I have some weird behavior.the console log tell me the body.x and body.y are 400 and 428, but the plate sprite move on screen. In the update function i fixed the x and y of my plate.body to simulate some pivot point. And a stop on the rotation.It is correct to do it that way ? Thank you in advance. Link to comment Share on other sites More sharing options...
mwatt Posted March 20, 2015 Share Posted March 20, 2015 I'm not sure I completely understand what you are saying, but I suspect this will help: plate.anchor.setTo(0.5, 0.5); This switches the control point of a sprite from the default top left to the middle. Link to comment Share on other sites More sharing options...
Gamble202 Posted March 20, 2015 Author Share Posted March 20, 2015 I want to do this: In fact, my problem is to block the rotation. My update code restraints my body.x and body.y correctly.When you make a sprite available for the P2physics, it's body.x/y became the center of the sprite.If I delete my restraint on the rotation > 0.2, my sprite correctly rotate around his center point when hit by the bowling ball.function update() { if(plate.body.x != 400){ plate.body.x = 400; } if ( plate.body.y != 428){ plate.body.y = 428; }}How can I stop the sprite rotation when body.rotation > 0.2 or body.rotation < -0.2 ? Link to comment Share on other sites More sharing options...
valueerror Posted March 21, 2015 Share Posted March 21, 2015 body.setZeroRotation() If this Body is dynamic then this will zero its angular velocity. Link to comment Share on other sites More sharing options...
Gamble202 Posted March 27, 2015 Author Share Posted March 27, 2015 Thank you, I will try that and post the code ! Link to comment Share on other sites More sharing options...
Recommended Posts