- Home /
Question by
bm212 · Dec 14, 2010 at 11:12 PM ·
rotationquaternionslerp
What's the correct way of smoothly rotating from an initial to a target position over several frames?
Say for example I want to rotate my object from an inital rotation to a final one over a several frames.
Is the below code snippet the right way to do this? If not, how should I go about this? (assume I've set myStartTime to Time.realtimeSinceStartup when I started doing the rotation, and that initialRotation and finalRotation have been defined somewhere else as well)
void Update() { float elapsedTime = Time.realtimeSinceStartup - myStartTime;
float timeFraction = elapsedTime / 10.f;// take 10s to get from initialRotation to finalRotation
myGameObject.transform.rotation = Quaternion.Slerp(initialRotation, finalRotation, timeFraction);
}
Comment