# Interpolate Rotation value - how do i stop the actor rotating the 'wrong' way?

EwokPD
Member, PRO Posts:

**35**
Hello,

I have an actor that i want to point where it is shooting - imagine a triangle facing upwards with bullets coming out of the top part of the triangle... and three targets above it... one off centre to the left... one straight up and one to the right.

I am using vector to angle based off start XY coords for the triangle actor... and end XY coord for the target clicked.

I am then interpolating the triangles self.rotation to the angle i have generated above (+or- a correction factor needed to align the triangle properly) - eventually each of the three corners of the triangle will be able to target independently so each corner of the triangle with have a different correction factor.

Now this almost works - for two of the actors the triangle will rotate the shortest distance and target the target properly... for the other target the triangle spins the wrong way when interpolating to the target so takes the longer route which looks silly and need fixing. I am guessing the triangle is choosing to rotate the 'wrong' way due to the maths getting confused when the angle goes from 359 back to 0 - but am not sure how to fix it - can anyone offer any ideas please.

Should i have not explained myself properly please let me know and will upload some graphics to aid in the description.

I have an actor that i want to point where it is shooting - imagine a triangle facing upwards with bullets coming out of the top part of the triangle... and three targets above it... one off centre to the left... one straight up and one to the right.

I am using vector to angle based off start XY coords for the triangle actor... and end XY coord for the target clicked.

I am then interpolating the triangles self.rotation to the angle i have generated above (+or- a correction factor needed to align the triangle properly) - eventually each of the three corners of the triangle will be able to target independently so each corner of the triangle with have a different correction factor.

Now this almost works - for two of the actors the triangle will rotate the shortest distance and target the target properly... for the other target the triangle spins the wrong way when interpolating to the target so takes the longer route which looks silly and need fixing. I am guessing the triangle is choosing to rotate the 'wrong' way due to the maths getting confused when the angle goes from 359 back to 0 - but am not sure how to fix it - can anyone offer any ideas please.

Should i have not explained myself properly please let me know and will upload some graphics to aid in the description.

## Comments

2,861currentRotation+(((targetAngle-currentRotation)+180)%360)-180

For example, to get an arrow actor to point at the mouse you could use the following equation in an interpolate behavior:

self.Rotation +(((vectorToAngle(game.Mouse.Position.X-self.Position.X, game.Mouse.Position.Y-self.Position.Y)-self.Rotation )+180)%360)-180

35352,8619,9342,861Actually, my very first post on this forum was about this exact same issue:

http://forums.gamesalad.com/discussion/28229/be-an-angel-fix-my-angle-stop-rotating-the-long-way-round-to-a-given-angle/p1

And 731 posts later -- its still my most fun discovery.

The thing I really like about GameSalad is that it is so easy to use and to experiment with. GameSalad makes it easy to think about the math because it makes all the other development stuff so freakin easy! And the built in functions make the math relatively easy too.