What's missing (I think or if not more) is that the follower need to know what's the shortest way to the target, i.e left rotating or right rotating. Now if angleToTarget is 350 degrees and rotationAngle (the followers current angle) is 0 degrees, it will turn all the way around instead of just backing -10 degrees. I think I need to put in a if-statement to check this, something like (rotationAngle-angletoTarget) > 180. I tried to search but couldn't find a understandable solution on this.

Just calculate how much your angle has to increase (in one direction) in order to get to the angle you want. Then, if the angle is greater than Pi, you only have to decrease the angle by 2*Pi (full circle).

[edit]

Essentially, what you wrote, minus the else clause (because the rotation angle should never be below 0). Also, you have to deduct by 2*Pi, instead of Pi.

Kalle Zander
Greenhorn

Joined: Nov 16, 2010
Posts: 28

posted

0

Stephan van Hulst wrote:Just calculate how much your angle has to increase (in one direction) in order to get to the angle you want. Then, if the angle is greater than Pi, you only have to decrease the angle by 2*Pi (full circle).

[edit]

Essentially, what you wrote, minus the else clause (because the rotation angle should never be below 0). Also, you have to deduct by 2*Pi, instead of Pi.

Ah, ok. Yes I saw now the 2*PI mistake by the way too.

No, you shouldn't have 2*Pi in the while clause. If the angle is greater than 180 degrees, you have to deduct 360 degrees, see?

Kalle Zander
Greenhorn

Joined: Nov 16, 2010
Posts: 28

posted

0

Stephan van Hulst wrote:No, you shouldn't have 2*Pi in the while clause. If the angle is greater than 180 degrees, you have to deduct 360 degrees, see?