If i had, say, a turret that i wanted to face a target GameObject using a function TurnDir(float dir) that turns the turret at a constant rate in the dir provided (1 or -1, for right and left), how would i determine the direction to turn in order to face the target?
(i want to avoid using Lerp or simply snapping the turret to face the right way)
Certainly you know the location of the target. You probably know the turret’s center. Do you have a point for the turret’s gun as it spins around, or an angle of rotation?
If you have an angle, in degrees for example, then what is the angle to the target? You can get that with Mathf.Arctan2( y, x ) * Rad2Deg. You can then compare the angles.
Now, what you’re really asking is which is the shortest rotation, because a turret than can spin repeatedly could point to the target from either direction of spin, but which is shorter?
You may have to “normalize” the angles, depending on what you get from the turret what it really means. The return from Arctan2( y, x ) assumes that a positive direction of rotation is counterclockwise, and zero degrees is a point on the X axis (where Y is zero). That may not be exactly what your turret is telling you, it might assume that 0 degrees is a point on the Y axis. Whatever the case, discover which it is and “normalize” or “adjust” that so they match. These two examples I mention are out of alignment by 90 degrees, and it may be that your turret rotation is positive clockwise, so if that were the case you’d have to convert the turret with something like ta = 180 - a (or possibly ta = 360 - a, depending on what range the turret returns to you). Then, you’d have to decrement ta by 90 to make it match the orientation of Mathf.Arctan2( y, x ).
That will let you directly compare the angle of the turret with the angle to the target, and choose if clockwise or counterclockwise is a shorter rotation.