# Rotation movement

**URL:** https://discourse.processing.org/t/rotation-movement/40509
**Category:** Coding Questions
**Created:** [January 8, 2023, 10:59am UTC](https://discourse.processing.org/t/rotation-movement/40509 "2023-01-08T10:59:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ctremblay](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@ctremblay](https://discourse.processing.org/u/ctremblay)
#### Post date: [January 8, 2023, 10:59am UTC](https://discourse.processing.org/t/rotation-movement/40509/1 "2023-01-08T10:59:30Z")

</div>

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

```auto
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

```auto
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;
  }
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 8, 2023, 12:07pm UTC](https://discourse.processing.org/t/rotation-movement/40509/2 "2023-01-08T12:07:28Z")

</div>

> [@ctremblay](#):
>
> ```auto
> .... cos(r) * spd;
> pos.y += sin(r) * spd;
> 
> ```

Missing radians() here?

---

<div class="post-metadata">

### Author: ![ctremblay](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@ctremblay](https://discourse.processing.org/u/ctremblay)
#### Post date: [January 8, 2023, 12:08pm UTC](https://discourse.processing.org/t/rotation-movement/40509/3 "2023-01-08T12:08:47Z")

</div>

i’ll try and add radians. ty
