Created
September 21, 2016 06:56
-
-
Save unitycoder/eedee9c452fc2e899b488f8569034b36 to your computer and use it in GitHub Desktop.
Quaternion Rotation Lerp with IEnumerator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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