Rotation problem

Hello,

I am using this code to rotate a GameObject when the player pushes a button:

private void Rotate()
	{
		if(Input.GetKey(KeyCode.A))
		{
			transform.Find("Graphics").Rotate(0,180,0);
		}
		if(Input.GetKey(KeyCode.D))
		{
			transform.Find("Graphics").Rotate(0,0,0);
		}
	}

but when i press the “a”-button, the object starts rotating to random y-directions (like 180.0037, 0.003726649 or 180.004) but never stays at the desired y-value 180.

I am using no other code on this object.
Do you know, what is wrong with this?

It’s your gameobject “Graphics” rotation set to (0, 0, 0)? If i’m not wrong, the Rotate function “add” the rotation.

The rotations of the object “Graphics” and the root object are both set to (0,0,0).

Try using this http://unity3d.com/support/documentation/ScriptReference/Transform-rotation.html which set’s the rotation, rather than rotating the object. or else put “* Time.deltaTime” into your brackets and see if that solves anything

Nothing is actually wrong, it’s just standard floating-point imprecision. Rotations are stored internally as quaternions, and translating back and forth between euler angles isn’t 100% precise.

–Eric

How are you calling your Rotate function?

I am calling the Rotate function from ´the method Update, but using Quaternion.Euler and Quaternion.Slerp instead of Transform.Rotate solves the problem, thanks.

But what is the diffference between these functions?