smatthews1999 Posted September 2, 2015 Share Posted September 2, 2015 Here's my question. I want to make a P2 body move in the direction it is already pointing. I tried moveUp(), moveDown(), etc. but they (not surprisingly) only go up or down. I tried thrust() but it does not seem to work unless it is being applied repeatedly.. as in the Update section. Just for the heck of it I tried this.... for (var i = 0; i < 500; i++) mysprite.body.thrust(500); and it did what I want, but I feel that this is probably not the way I should do this. Is there a better way? Thanks,Sam Link to comment Share on other sites More sharing options...
buttonsrtoys Posted September 2, 2015 Share Posted September 2, 2015 Thrust is how it's done in the P2 examples. E.g., http://phaser.io/examples/v2/p2-physics/accelerate-to-object Link to comment Share on other sites More sharing options...
smatthews1999 Posted September 3, 2015 Author Share Posted September 3, 2015 Right. I guess what I was asking is how to do this without using the Update loop. Link to comment Share on other sites More sharing options...
buttonsrtoys Posted September 3, 2015 Share Posted September 3, 2015 Sorry, I should have read your questions more closely. From what I've seen in the examples, you need extract the body's direction (i.e., rotation) and apply XY explicitly. E.g., for constant velocity:bug.body.velocity.x = Math.cos(bug.rotation) * BUG_SPEED;bug.body.velocity.y = Math.sin(bug.rotation) * BUG_SPEED;To accelerate, there's a good example here http://phaser.io/examples/v2/p2-physics/accelerate-to-object. Below's a snippet:obj1.body.force.x = Math.cos(angle) * speed; // accelerateToObject obj1.body.force.y = Math.sin(angle) * speed; Link to comment Share on other sites More sharing options...
Recommended Posts