Hi,
I have a question about using Slerp method. I’m using it to rotate an object so that it will be looking at a point. However as far as I know, when progress is 1, Slerp will be done. But in my case it turns towards the point I want when progress is 0.5f. And If I continue turning until progress is 1, it turns back to its original rotation.
Actually my code is working in that way but I wonder why it doesn’t work as it should when slerp is called until progress is 1. Thanks in advance!
private IEnumerator TurnTowardsFinalTrack_CO()
{
float progress = 0f;
Transform centerP = selectedRunway.GetRunwayCenterPoint();
Vector3 dirVector = -centerP.position + transform.position;
Quaternion targetRotation = Quaternion.LookRotation(dirVector, Vector3.forward);
Vector3 correctionVector = Vector3.zero;
while (progress < 0.5f) //weirdly works in that way
{
transform.transform.rotation = Quaternion.Slerp(transform.transform.rotation, targetRotation, progress);
correctionVector.z = transform.transform.eulerAngles.z;
transform.eulerAngles = correctionVector;
progress += Time.deltaTime;
yield return null;
}
}