Turn page, smooth rotate

Hi everyone,

I ran again into something I am yet to understand and learn how to achieve : smooth rotate an object from an angle to another. What I want to do in this case is have a button rotate (turn) a page (game object); ideally it should have an array of pages but for now I want to get around this smooth rotate thing. A page should slowly rotate 180 degrees when I press a button, with an exposed speed variable.

Here’s what I use and doesn’t really do the trick:


var page1 : GameObject;
var page2 : GameObject;
var page3 : GameObject;
var smooth = 2.0;

function OnGUI () 


     if (GUI.Button(Rect(0,0,50,30),"Next"))
        	page2.transform.Rotate (0, 0, -180);        	

	  if (GUI.Button(Rect(0,200,50,30),"Previous"))
        		page2.transform.Rotate (0, 0, 180*smooth*Time.deltaTime);        	


Spherical linear interpolation is what you need in this case.
Luckily Unity has this built into for you :slight_smile:

Check out Quaternion.Slerp and its code sample in the documentation.