# Can't get my object to move around axis

**URL:** <https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990>\
**Category:** Coding Questions\
**Created:** [May 7, 2019, 7:21am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990 "2019-05-07T07:21:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shemozzles](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shemozzles](https://discourse.processing.org/u/Shemozzles)\
**Post date:** [May 7, 2019, 7:21am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/1 "2019-05-07T07:21:16Z")

</div>

Hey guys,

I have this piece of code where I am trying to move a spaceship around the 0 axis. It also moves up and down. However, the further I move it up, the greater the turning circle is. I have tried various methods but cannot get it to where I want it to at the moment. If anyone could give me a hint that would be great!

```auto
int angle = 0;
PImage ship;
PVector shipVelocity, shipLocation;

void setup() {
ship = loadImage("asteroid_ship.png");
background(0);
smooth();
size(500,500);
noStroke();
shipVelocity = new PVector(1,1);
shipLocation = new PVector(1,1); 
}

void draw() {
if(keyPressed){
    if (key == CODED) {
        if (keyCode == RIGHT) {
            angle+=5;
        } 
        else if (keyCode == LEFT) {
           angle-=5;
        }
        else if (keyCode == UP) {
           shipLocation.y -= shipVelocity.y; 
        }
        else if (keyCode == DOWN) {
           shipLocation.y += shipVelocity.y; 
        }
    }
}
background(0);
translate(250,250);
rotate(radians(angle));
image(ship, shipLocation.x, shipLocation.y, 32, 38);
}
void keyPressed() {

}

```

---

<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:** [May 7, 2019, 7:48am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/2 "2019-05-07T07:48:11Z")

</div>

Use image with 0,0

Put the coordinates into translate 250+…

set imageMode (CENTER); in setup ()

---

<div class="post-metadata">

**Author:** ![Shemozzles](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shemozzles](https://discourse.processing.org/u/Shemozzles)\
**Post date:** [May 7, 2019, 11:27am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/3 "2019-05-07T11:27:02Z")

</div>

Hi, thanks for the response.

> [@Chrisir](#):
>
> Put the coordinates into translate 250+…

I tried changing those things. Still stuck on this translate function though and the hint that you gave me. Tried various additions of angles and using cosine and sine but still not working. The image is moving well, but the greater it moves from the original point, the less it spins around its origin.

---

<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:** [May 7, 2019, 11:31am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/4 "2019-05-07T11:31:02Z")

</div>

set imageMode (CENTER); in setup ()

---

<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:** [May 7, 2019, 11:35am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/5 "2019-05-07T11:35:34Z")

</div>

```auto

int angle = 0;
PImage ship;
PVector shipVelocity, shipLocation;

void setup() {
  size(500, 500);

  ship = loadImage("img.png");
  background(0);
  smooth();

  noStroke();
  shipVelocity = new PVector(1, 1);
  shipLocation = new PVector(1, 1);

  imageMode(CENTER);
}

void draw() {
  if (keyPressed) {
    if (key == CODED) {
      if (keyCode == RIGHT) {
        angle+=5;
      } else if (keyCode == LEFT) {
        angle-=5;
      } else if (keyCode == UP) {
        shipLocation.y -= shipVelocity.y;
      } else if (keyCode == DOWN) {
        shipLocation.y += shipVelocity.y;
      }
    }
  }
  background(0);
  translate(250+shipLocation.x, 250+shipLocation.y);
  rotate(radians(angle));
  image(ship, 0, 0, 32, 38);
}
void keyPressed() {
}

```

---

<div class="post-metadata">

**Author:** ![Shemozzles](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shemozzles](https://discourse.processing.org/u/Shemozzles)\
**Post date:** [May 7, 2019, 11:35am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/6 "2019-05-07T11:35:43Z")

</div>

Hi, I just tried that but it still does the same thing.

---

<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:** [May 7, 2019, 11:36am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/7 "2019-05-07T11:36:10Z")

</div>

posted my entire code now

works for me

image must be with 0,0

```auto
  image(ship, 0, 0, 32, 38);

```

**By the way**

by the way… `image()` with 5 parameters is very time-consuming for the processor

instead use `resize()` in setup() once and for all

[https://www.processing.org/reference/PImage\_resize\_.html](https://www.processing.org/reference/PImage_resize_.html)

then say

```auto
  image(ship, 0, 0);

```

with only 3 parameters

Chrisir

---

<div class="post-metadata">

**Author:** ![Shemozzles](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shemozzles](https://discourse.processing.org/u/Shemozzles)\
**Post date:** [May 7, 2019, 11:39am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/8 "2019-05-07T11:39:53Z")

</div>

> [@Chrisir](#):
>
> int angle = 0; PImage ship; PVector shipVelocity, shipLocation; void setup() { size(500, 500); ship = loadImage(“img.png”); background(0); smooth(); noStroke(); shipVelocity = new PVector(1, 1); shipLocation = new PVector(1, 1); imageMode(CENTER); } void draw() { if (keyPressed) { if (key == CODED) { if (keyCode == RIGHT) { angle+=5; } else if (keyCode == LEFT) { angle-=5; } else if (keyCode == UP) { shipLocation.y -= shipVelocity.y; } else if (keyCode == DOWN) { shipLocation.y += shipVelocity.y; } } } background(0); translate(250+shipLocation.x, 250+shipLocation.y); rotate(radians(angle)); image(ship, 0, 0, 32, 38); } void keyPressed() { }

Ahhh, my was issue with the translate section not with the imageMode in the end. I was overthinking it and using sine and cosine with the translate function.

Thank you so much! I really do appreciate your help (apologies for sounding so daft). I’ve been spending the last hour figuring this out.

---

<div class="post-metadata">

**Author:** ![Shemozzles](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shemozzles](https://discourse.processing.org/u/Shemozzles)\
**Post date:** [May 7, 2019, 11:40am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/9 "2019-05-07T11:40:34Z")

</div>

Thanks for that tip!

---

<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:** [May 7, 2019, 11:41am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/10 "2019-05-07T11:41:24Z")

</div>

You are welcome!

Chrisir

---

<div class="post-metadata">

**Author:** ![Shemozzles](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shemozzles](https://discourse.processing.org/u/Shemozzles)\
**Post date:** [May 7, 2019, 11:20pm UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/11 "2019-05-07T23:20:45Z")

</div>

Hello again,

So I have a new problem now. I am attempting to move it in the direction that it is pointing. So far, I have made some progress, but it seems to just be a roll of the dice in terms of where it is going.

```auto
        shipVelocity = PVector.fromAngle(angle + HALF_PI);
        shipLocation.add(shipVelocity);

```

Tried using this as well as adding cosine and sine to each individual component of the Location PVector but it’s not making much of a difference. Any tips here? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Shemozzles](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shemozzles](https://discourse.processing.org/u/Shemozzles)\
**Post date:** [May 8, 2019, 1:06am UTC](https://discourse.processing.org/t/cant-get-my-object-to-move-around-axis/10990/12 "2019-05-08T01:06:12Z")

</div>

Update: All good! Realised that radians was causing my issue the whole time and also making my angle and int not a float was not helpful either. It now spins and moves in the correct direction 🙂
