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

Member, PRO Posts: 35
edited September 2012
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.

• Member, Sous Chef, PRO Posts: 2,861
The general formula would go something like:
currentRotation+(((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
• Member, PRO Posts: 35
Thanks RT -i will give that a go now
• Member, PRO Posts: 35
That works like a charm...very much appreciated... it was frying my brain that problem! :P
• Member, Sous Chef, PRO Posts: 2,861