#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# my tower isn't turning as the balloon goes by.

edited June 2015

//my balloons and towers are (40, 40)

``````void drawTower() {

for (int i=w.balloonList.size(); i == -1; i--) {
Balloon balloon = w.balloonList.get(i);

if (dist(pos.x+20, pos.y+20, balloon.pos.x + 20, balloon.pos.y + 20) < radius) {
bPosX = balloon.pos.x;
bPosY = balloon.pos.y;
}
}
float angle = atan2(bPosY - (pos.y+20), bPosX - (pos.x+20)) + HALF_PI;

pushMatrix();
translate(pos.x + 20, pos.y + 20);//origin
rotate(angle);
image(monkey, -20, -20);
popMatrix();

if (mouseX > pos.x && mouseX < pos.x+40
&& mouseY > pos.y && mouseY < pos.y+40) {
noStroke();
fill(0, 0, 155, 60);//sets a blue colour slightly visible
}
}
``````
Tagged:

• this is too briefly written

what is pos.x ?

why do you have monkey in line 14 ? Is that the tower?

• ``````Balloon balloon = new Balloon();
PVector pos=new PVector(222, 300); // tower / monkey

float bPosX;
float bPosY;

void setup () {
size(600, 600);
background(0);
}

void draw() {
background(0);
drawTower();
balloon.pos.x+=balloon.speed.x;
balloon.display();
}

void drawTower() {

//   = w.balloonList.get(i);

// if (dist(pos.x+20, pos.y+20, balloon.pos.x + 20, balloon.pos.y + 20) < radius) {
bPosX = balloon.pos.x;
bPosY = balloon.pos.y;
// }
// } // for
float angle = atan2(bPosY - (pos.y+20), bPosX - (pos.x+20)) + HALF_PI;

pushMatrix();
translate(pos.x + 20, pos.y + 20);//origin
rotate(angle);
text("monkey", -20, -20);
popMatrix();

if (mouseX > pos.x && mouseX < pos.x+40
&& mouseY > pos.y && mouseY < pos.y+40) {
noStroke();
fill(0, 0, 155, 60);//sets a blue colour slightly visible
}
}

// ==================================

class Balloon {

PVector pos=new PVector(0, 40);
PVector speed=new PVector(3, 0);

void display() {
ellipse(pos.x, pos.y, 6, 6);
}
//
} // class
//
``````
• did you change the angle or rotation info or did t just work?

• edited June 2015 Answer ✓

the if clause and the for loop are ending in line 9/10 in your code (the very first post)

thus only the last ball that is close enough (the dist() thing) can turn the tower

so I took out the dist() and the for-loop (so maybe you need to fix that part)

I haven't changed the rotation itself (the block between pushMatrix and popMatrix)

;-)