duck

Unity 3D Rotate from to over time coroutine example

Jan 12th, 2012
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. // Untested !
  2.  
  3. IEnumerator RotateFromTo (Transform t, Quaternion from, Quaternion to, float duration)
  4. {
  5.     float startTime = Time.time;
  6.     float endTime = startTime + duration;
  7.    
  8.    
  9.    
  10.     while (Time.time < endTime)
  11.     {
  12.         float i = Mathf.InverseLerp(startTime, endTime, Time.time);
  13.         t.rotation = Quaternion.Slerp(from, to, i);
  14.     }
  15.  
  16. }
  17.  
  18. IEnumerator RotateTo (Transform t, Quaternion to, float duration)
  19. {
  20.     RotateFromTo(t, t.rotation, to, duration);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment