jagd Posted February 27, 2015 Share Posted February 27, 2015 Hi, I'm making a game where the player controls a Mars Rover from a top-down perspective. I'm using the WASD control scheme and I'm trying to make it so the rover moves like a car. If you aren't sure what I mean, imagine looking down at a car performing a K-turn and you might know what I mean. I got this to work with Arcade Physics, even got it to work with groups. Now I don't know how to get it to work with P2 Physics. Here is my code:function MovePlayer(player, cursors, game){ //Player Basic Movement Controls //WASD declerations might be making things slower fyi. var W = game.input.keyboard.addKey(Phaser.Keyboard.W); var Al = game.input.keyboard.addKey(Phaser.Keyboard.A); var S = game.input.keyboard.addKey(Phaser.Keyboard.S); var D = game.input.keyboard.addKey(Phaser.Keyboard.D); if (Al.isDown) { //player.body.rotateLeft(100); player.body.angularVelocity = -5; } else if (D.isDown) { //player.body.rotateRight(100); player.body.angularVelocity = 5; } else { player.body.setZeroRotation(); } if (W.isDown) { player.body.thrust(450); } else if (S.isDown) { player.body.reverse(300); } else { player.body.damping = 0.75; } if (player.body.velocity > 1.0) { player.body.velocity = 1.0; } }Right now the rover moves like it's in a slip'n'slide. Holding down forward and left or forward and right keys results in the rover spinning around in place. Imagine an object facing the center of a circle and just rotating around the center. Same thing using the reverse key. I don't know how to get it to work right. Any ideas? Link to comment Share on other sites More sharing options...
stupot Posted February 28, 2015 Share Posted February 28, 2015 Have a look at this for inspiration: http://digitalsynapsesoftware.blogspot.co.uk/2014/11/combining-phaser-and-threejs-to-make.html Link to comment Share on other sites More sharing options...
jagd Posted March 2, 2015 Author Share Posted March 2, 2015 Yeah thanks, so the complete demo available there looks like what I want (except I'm using 2D mode, not whatever 2.5D mode they are using), but that page doesn't have any of the code showing how to do it. Link to comment Share on other sites More sharing options...
Milton Posted March 2, 2015 Share Posted March 2, 2015 Javascript is completely open source Just look at the sources with Developer Tools or whatever... Link to comment Share on other sites More sharing options...
jagd Posted March 3, 2015 Author Share Posted March 3, 2015 Oh, shoot, I forgot about that! So I looked at the code with developer tools and am still confused as to how they did it. When I did this in Arcade physics I used VelocityfromAngle. Does anyone know if there is an equivalent to VelocityfromAngle in P2? Link to comment Share on other sites More sharing options...
Recommended Posts