[Solved] Checking when a gradual rotation has finished

Hi there,

This must be a really stupid question, but my trigonometry is very rusty so I’m having trouble sorting this out:

I am making a character rotate on the Y-axis using Mathf.SmoothDampAngle(). I need to know when it has fully rotated to its destination.

Here’s a snippet from my code:

Vector3 delta = targetPosition - transform.position;
float targetAngle = Mathf.Atan2(-delta.z, -delta.x);
float currentAngle = transform.localEulerAngles.y;
currentAngle = Mathf.SmoothDampAngle(currentAngle, -targetAngle * Mathf.Rad2Deg - 90, ref rotationVelocity, rotationSmoothTime);
transform.localEulerAngles = new Vector3(0, currentAngle, 0);

Help anyone? :sweat_smile:

Never mind, I figured it out:

Vector3 delta = position - transform.position;
float targetAngle = -Mathf.Atan2(-delta.z, -delta.x) * Mathf.Rad2Deg - 90;
float currentAngle = transform.localEulerAngles.y;
currentAngle = Mathf.SmoothDampAngle(currentAngle, targetAngle, ref rotationVelocity, rotationSmoothTime);
transform.localEulerAngles = new Vector3(0, currentAngle, 0);
hasReachedOrientation = Mathf.Abs(Mathf.DeltaAngle(currentAngle, targetAngle)) < rotationMargin;