Rotation Bug.

Hi, I’m trying to rotate the camera 90 degrees smoothly. However, when I do I either am off by a few decimal points, or it just keeps going and going. The code I am using is as follows:

function Rotate ()
{
	//rotating = true;
	var xRotation = 0F;
	while (rota)
	{
		var deltaDegrees = rotateSpeed * Time.deltaTime;
		Debug.Log(xRotation);
		if (xRotation >= 90)
		{
			deltaDegrees = 90 - xRotation;
			rota = false;
			break;
		}
		else xRotation += deltaDegrees;
		
		transform.Rotate(Vector3(0, 0-deltaDegrees, 0));
		yield;
	}
	xRotation = 0F;
}

The problem is in the yield. If I turn it off, it just jumps to the position after a delay. If I leave it there it rotates slowly, and then quicker and quicker. Can I have some help? One more thing, the code that uses rotate is:

Rotate();
// Later in the code
if(!rota  Input.GetKeyUp(KeyCode.LeftArrow))
{
	rota = true;
}

All of this is in update();.

you should call Rotate() only once. Right now you are calling every Update() cycle after if(!rota Input.GetKeyUp(KeyCode.LeftArrow))
is true and the first Rotate() finishes.
so do this:

// Later in the code
if(!rota  Input.GetKeyUp(KeyCode.LeftArrow))
{
                Rotate();
	rota = true;
}

You can’t yield in Update, and shouldn’t be using Update for this sort of thing anyway. http://www.unifycommunity.com/wiki/index.php?title=MoveObject

–Eric

What function should I use then?

You are using yield in the Rotate() function which is fine.
Just do what I told you above.

But Eric told me not to use update for this sort of thing. Is he right? Is there a better way to do the whole thing?

That won’t really work, because the request was to rotate by 90 degrees exactly.

Yes, use the script I linked to.

–Eric