# Move sprite according to angle

## Recommended Posts

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!

##### Share on other sites

so i forgot the equasion fr a second but found it here:

vx = v * cos(angle)
vy = v * sin(angle)

the angle may be in radians, which you can convert fairly easily.