Shermz345

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


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.