Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created September 21, 2016 06:56
Show Gist options
  • Select an option

  • Save unitycoder/eedee9c452fc2e899b488f8569034b36 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/eedee9c452fc2e899b488f8569034b36 to your computer and use it in GitHub Desktop.
Quaternion Rotation Lerp with IEnumerator
// rotate target transform from Quaternion A to Quaternion B, within duration
// to call
StartCoroutine(RotateLerp(transform, Quaternion.Euler(0,90,0)));
IEnumerator RotateLerp(Transform target, Quaternion endRot)
{
float duration = 1.5f;
var startRot = target.rotation; // current rotation
for (float timer = 0; timer < duration; timer += Time.deltaTime)
{
target.rotation = Quaternion.Slerp(startRot, endRot, timer / duration);
yield return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment