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 this post

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×

• Recently Browsing   0 members

No registered users viewing this page.