If I have an object facing in a direction that needs to turn to match the angle of another object, is there a formula to determine the shortest type of rotation (clockwise vs. counterclockwise)?
This is NOT the same thing as determining the shortest way to turn to FACE another object, which is the formula I ended up creating. I need my object to MATCH the angle of another object.
If you're curious about the facing formula, here it is:
f
(Player.X - cos(Target.Angle)) * sin(Player.Angle) > (Player.Y - sin(Target.Angle)) * cos(Player.Angle)
...then Clockwise is the shortest.
Otherwise, counterclockwise.
For those who don't understand what the above formula does, it basically draws a line behind the player and then determines which side of that line the target is on. However, the above formula made sense to me because I am able to think of it in cartesian coordinates and not polar ones.
I'm trying to think of a way to determine the shortest way to match the angle of another object, and I can't seem to find a cartesian way to think of it.
EDIT: Current line of thinking is:
bs() = absolute value
If
abs(Player.Angle - Target.Angle) > abs(Player.Angle + 180 - Target.Angle)
... then Counterclockwise
However, this fails if Target.Angle = 0, so this can't be it, even though it seems to work for a lot of cases.