Tommy_ Posted July 31, 2018 Share Posted July 31, 2018 in this lab example there is something like snap to 45,135, -45, -135 angles. if you active debug mode and try to move to any direction but the ones i said you will notice it. like in the attach i'm aiming at bottom but i'm moving to 45. and it's stuck at 45. How can i make it to move to the angle i'm aiming for? like this (tried to change velocityFromRotation to velocityFromAngle but nothing changed) sorry I'm new and trying my best to explain it. tried to change it if (cursors.up.isDown) { this.physics.velocityFromRotation(ship.rotation, 600, ship.body.acceleration); } Link to comment Share on other sites More sharing options...
Tom Atom Posted July 31, 2018 Share Posted July 31, 2018 Try this: if (cursors.up.isDown) { //this.physics.velocityFromRotation(ship.rotation, 600, ship.body.acceleration); ship.setVelocity(Math.cos(ship.rotation) * 600, Math.sin(ship.rotation) * 600); // 1 } else { ship.setAcceleration(0); ship.setVelocity(0,0); // 2 } In physics, you use acceleration to calculate new velocity and velocity to get new position. If you are driving car and accelerating for some time, your velocity increases. When you yake the foot out of the gas, your acceleration is 0, it does not increase velocity and your velocity is constant (unless there is inplemented something like friction or drag, which will slow you down). What you need is immediate change in velocity - it is commented as // 1. You can also add line // 2 to immediately stop ship if not holding up key... but it looks ugly (it is like you not only put foot out of gas, but stomped on break in the same time) Alternatively, you can change original line to this: this.physics.velocityFromRotation(ship.rotation, 600, ship.body.velocity); Tommy_ 1 Link to comment Share on other sites More sharing options...
Tommy_ Posted July 31, 2018 Author Share Posted July 31, 2018 Thanks for explanation. but the problem is when using this.physics.velocityFromRotation(ship.rotation, 600, ship.body.acceleration); with second argument you could set "how long takes to reach the max speed" and setMaxVelocity was the max speed. this.physics.velocityFromRotation(ship.rotation, 600, ship.body.velocity); but when using this, the second argument is the max speed!! Link to comment Share on other sites More sharing options...
samme Posted August 1, 2018 Share Posted August 1, 2018 http://labs.phaser.io/edit.html?src=src\physics\arcade\asteroids movement.js Link to comment Share on other sites More sharing options...
Recommended Posts