Shermz345 Posted December 24, 2017 Share Posted December 24, 2017 Hi, I've been trying to figure out how to move a sprite in the direction it is facing. I was originally going to use the p2js "thrust" function, but it caused a small jitter with the camera. I then tried to use the Arcade "velocityFromAngle", but it was not accurate enough. Here is the code I have playerBoat.prototype.update = function () { if(wasd.up.isDown ) this.speed += 2; else this.speed -=2; if(this.speed > 0){ //MATH } if(wasd.left.isDown && this.speed > 0){ this.angle -= 1; } else if(wasd.right.isDown && this.speed > 0){ this.angle += 1; } As someone who was never too strong in math, I am a little bit confused as to how to relate the angle and speed to do what I'm trying to do. I'm assuming it's something with vectors, but I could use some direction. Thanks in advance! Link to comment Share on other sites More sharing options...
Nivoset Posted January 1, 2018 Share Posted January 1, 2018 so i forgot the equasion fr a second but found it here: http://www.idevgames.com/forums/thread-7150.html vx = v * cos(angle)vy = v * sin(angle) the angle may be in radians, which you can convert fairly easily. Link to comment Share on other sites More sharing options...
Recommended Posts