Yes, I did read your post. And there’s nothing about your post that says you knew about ‘SignedAngle’, nor what your previous knowledge of it has to do with my reading your post. Nor in your post do you suggest you knew the problem is with RotateTowards.
I suspect what you meant by if I read your post is that my answer was not satisfactory because I didn’t give you example code or something.
But yeah, don’t use Vector3.RotateTowards.
Get the signed angular direction, and rotate by that.
If you don’t know how to rotate by a signed angle… well there’s lots of ways to. I use Quaternions personally:
//get targAngle
var dirOfTarget = (target.position - this.transform.position);
dirOfTarget.y = 0f; //remove any vertical
float targAngle = Vector3.SignedAngle(dirOfTarget, this.transform.parent.forward, Vector3.up);
//clamp targAngle
if (targAngle < -this.angularRange) targAngle = -this.angularRange;
if (targAngle > this.angularRange) targAngle = this.angularRange;
//get currentAngle
float currentAngle = Vector3.SignedAngle(this.transform.forward, this.transform.parent.forward, Vector3.up);
//find our delta from current to targ
var delta = targAngle - currentAngle;
//get a speed to move in that direction smoothly
delta = Mathf.Min(this.turnSpeed * Time.deltaTime, Mathf.Abs(delta)) * Mathf.Sign(delta);
//rotate towards
this.transform.localRotation*= Quaternion.Euler(0f, -delta, 0f); //we have to negate delta because annoyingly Unity has SignedAngle upside down
If you need a forward vector. Like in your code… that last line could be:
Vector3 newDir = Quaternion.Euler(0f, -delta, 0f) * this.transform.forward;
The fundamental concept is like.
Think of a number line:
-5 . . . . . 0 . . . . 5
If I want to go from 4 to -3, how much do I have to move by (add to 4) to get to -3. Well it’s:
3 + x = -4
x = -4 - 3
x = -7
Or effectively it’s:
delta = targ - current
So we move 7 places left (-) from 4 to -3.
Well… all we need to do with the angles is unravel the rotation into a number line (hence the SignedAngle). Get the delta. And rotate to the target by that delta.