# Help With Simple Rotation

I’m struggling to get my head around this, but basically - I have a ResetRotation function in where I want it to:

yield WaitForSeconds(2);

and then reset the Y rotation to ‘0’ over time (so it looks like its animated).

How would one go about doing that?

Thanks

it’s probably be better if u use the animation tab in unity, there a good basic tutorial on the unity site that shows u how to do it.
check here for the videos : http://unity3d.com/support/resources/tutorials/video-animation-view

or maybe what u can do is something like this

``````  transform.Rotate(Vector3.right * Time.deltaTime);
``````

in this case it says its rotates the object on the x axes by 1 degree per sec, so not sure how to get exactly what u want myself but its a start.

If you could keep track of how far you are rotating as you are doing it, then you could just rotate the same amount again but negative.

Check documentation on how to use RotateTwoards. Or you can use

``````var reset : boolean;
function Update(){
if(reset )
{
transform.Rotate(0,Mathf.Lerp(transform.rotation.y, 0,Time.time),0);
}
}
``````

something like that would rotate it back to 0 on the y axis over 1 second whenever reset is true.

This is probably easiest done with a coroutine.

Typed in browser - may or may not compile

``````function ResetRotation(){
var oldY : float = transform.eulerAngles.y;
var t : float = 0.0;//animation time
var speed : float = 1.0; //how fast you want the rotation to happen
while(t < 1.0){
transform.eulerAngles.y = Mathf.Lerp(oldY, 0.0, t); //rotate to the new position
t += Time.deltaTime * speed;  //animate the time variable
yield; //yield til the next frame
}
}
``````