Jump to content

Move sprite according to angle


Shermz345
 Share

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!

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...