You're still using the exponential ease-out lerp I told you about previously. Whenever you use the pattern:
current = lerp(current, target, sharpness);
...you create a negative feedback loop. (See how "current" appears as both the input AND the output?)
That makes the lerp behave fastest when the object first starts moving, then slow to a crawl as it gets closer to its target. Combined with an ease-in-out curve being passed to the sharpness parameter (which is more like a rate of change, not a measure of progress), and you get a very strange motion that is not at all what you intended.
One way you can solve this is by storing some state about when you started this motion and which way you were facing at the time:
if (Vector3.Dot(forward, toOther) < 0) { // Snapshot our initial rotation only when we *begin* our return journey. if (returnProgress < 0f) { returnProgress = 0f; rotationBeforeReturning = transform.rotation; } returnProgress = Mathf.Clamp01(returnProgress + Time.deltaTime/returnDuration); // Note that "transform.rotation" does not appear on the right-hand side. // That means we're no longer using an exponential ease-out lerp, and the // last parameter really is a measure of progress, not a diminishing rate of change. transform.rotation = Quaternion.Lerp(rotationBeforeRetuning, originalRotation, curve.Evaluate(returnProgress)); } else { // Terminate the attempt to return to the original orientation, // so that we re-start it from scratch the next time we lose sight. returnProgress = -1f; // The rest of your else case goes here... }
But actually I think you can reimplement your whole script more simply using the built-in SmoothDamp function, which handles an ease-in-out movement toward a target, maintaining a continuous velocity (so eg. a character's head doesn't suddenly lurch or snap to an abrupt stop).
There's no Quaternion.SmoothDamp to damp rotations directly, but we can use Vector3.SmoothDamp to damp our look direction as it moves around the unit sphere, then construct a quaternion from that.
public class EasedLookAt : MonoBehaviour { public Transform target; // Keep this low to make the tracking tight for small target movements. public float lookChangeDuration = 0.1f; // Use this to limit our top rotation speed when making a big turn. // It's measured in "approximately" radians per second. public float maxLookSpeed = 5f; Vector3 lookVectorVelocity; Vector3 originalLookDirection; private void Start() { originalLookDirection = transform.forward; } void LateUpdate() { Vector3 desiredLook = (target.position - transform.position).normalized; if (Vector3.Dot(desiredLook, transform.forward) < 0) { desiredLook = originalLookDirection; } var look = Vector3.SmoothDamp(transform.forward, desiredLook, ref lookVectorVelocity, lookChangeDuration, maxLookSpeed); transform.rotation = Quaternion.LookRotation(look); } }
In terms of your use of the site, I notice you've left a long chain of zero-vote, unanswered, or deleted questions - quite a few struggling with different aspects of this look mechanic.
I would recommend asking fewer questions that say "my code is broken, why / how do I fix it?" - if your code is broken, it might not be the best starting point for accomplishing your goal. Fixing one problem might just reveal another, and focusing on individual bugs can distract from the opportunity to find a better overall strategy.
Instead, I would recommend trying to ask goal-focused questions. For example:
How to look at a target and return to neutral when it's out of sight, with easing?
As you can see above, an answer to such a question can actually be much simpler than playing whack-a-mole trying to fix all the problems with a broken script.
And they're usually more pleasant to answer, too, so you might find you get better engagement from other users with this strategy.