Rotation movement

I’m trying to make a fun game & watched a few videos on rotation, but my rotation aint being consistant. I drew a red line where it first started moving so i could check, but now it moving backwards sideways it barely follows the path it went the last time before rotation. I want to press w or up and the ship moves upwards. i’ll make the red line point desired direction.

sketch

Mouse m;
void setup(){
  size(600,600);
  m = new Mouse();
}

void draw(){
  background(0);
  m.move();
  m.show();
}

void keyPressed(){
  if (key == 'w'){m.spd = 1;}
  if (key == 'a'){m.r -= 1;}
  if (key == 'd'){m.r += 1;}
}

void keyReleased(){
  if (key == 'w'){m.spd = 0;}
}

mouse

class Mouse{
  PVector pos;
  int health = 1;
  int r = 0;
  int spd = 0;
  
  Mouse(){
    pos = new PVector(300,300);
    //pos = new PVector(random(width),random(height));
  }
  
  void show(){
    pushMatrix();
      translate(pos.x,pos.y);
      rotate(radians(r));
      noStroke();
      int s = 20;
      triangle(0,-s,-s,s,s,s);
      stroke(255,0,0);
      line(0,0,0,-100);
    popMatrix();
  }
  
  void move(){
    pos.x += cos(r) * spd;
    pos.y += sin(r) * spd;
  }
}

Missing radians() here?

i’ll try and add radians. ty

1 Like