So not sure if this would belong in the lounge or here since it is technically not a programming question and is more maths oriented. So if it needs to be moved just let me know.
Anyways on to the problem at hand. It has to do with game AI and specifically getting the AI to rotate correctly. I am trying to create the base method that handles AI rotation. It will take a target orientation and rotate the entity from it's current orientation to that target orientation.
Let's say we have a Entity that has the orientation of 1.57079 Radians (90 Degrees) and we want to change that Entity's orientation to 0 Radians (0 Degrees). How would one find the correct way to rotate from just them two orientations (IE find the shortest rotation direction from a current orientation to a target orientation)?
As my implementation stands now the Entity rotates just fine I think but always in a clockwise rotation (Because I can't figure out how to determine the best rotation direction). For example using the previous number (1.57079 Radians to 0 Radians) the Entity will rotate all the way around 270 Degrees clockwise instead of rotating just 90 degrees counter-clockwise.
Hopefully that is enough to explain what I am having trouble with. I would post the method's code but currently do not have access to it until I am off work. Any helpful tips or hints would be much appreciated and I should also note that I am not the greatest with maths.
Also if there is a better way to implement this behavior I would love to hear suggestions about that also. I have thought about possibly projecting vectors a short distance forward from the current orientation and target orientation to figure out the rotation direction but not sure if that is a good way to implement it.
1) Deduct target rotation from current (If I want to rotate from π to π/2 that makes result π/2)
2) Make resulting angle to fit in [−π; π] by adding or deducting 2π·n
3) Rotation is −(rsulting angle), so if my result was π/2 then rotation is -π/2 or 90° counte-clockwise