# How can I rotate an object to a specific angle over time.

I have looked at quaternions and slerp but it’s all really confusing to me for some reason. Ideally I want to have an object rotate from (0, 0, 0) to (0, 180, 0) over time. I tried to do it but it didn’t work because it could not convert vector3 to a quaternion.

Before I screwed up the code even more, it looked something like this:

``````//myObject 's  current rotation is (0, 0, 0)
Vector3 newRotation = (0,180,0);
if (Input.GetKey (KeyCode.A)) {
myObject.rotation = Quaternion.Slerp(myObject.rotation, newRotation , Time.time * 1);
}
``````

Honestly I would just like someone to explain why this doesn’t work and how I should do it instead, not do it for me. Thanks in advance.
}
}

There are many ways you can do this. Here are just a few

``````if (myObject != null)
{
StartCoroutine(RotateImage());
}

IEnumerator RotateImage()
{
float moveSpeed = 0.1f;
float y = 180;
while(myObject.transform.rotation.y < 180)
{
myObject.transform.rotation = Quaternion.Slerp(myObject.transform.rotation, Quaternion.Euler(0, 180, 0), moveSpeed * Time.time);
yield return null;
}
myObject.transform.rotation = Quaternion.Euler(0, 180, 0);
yield return null;
}
``````

or like this

``````if (myObject != null)
{
StartCoroutine(RotateImage());
}

IEnumerator RotateImage()
{
float moveSpeed = 0.1f;
while(myObject.transform.rotation.y < 180)
{
myObject.transform.rotation = Quaternion.Lerp(myObject.transform.rotation, Quaternion.Euler(0, 180, 0), moveSpeed * Time.time);
yield return null;
}
myObject.transform.rotation = Quaternion.Euler(0, 180, 0);
yield return null;
}
``````

or like this

``````if (myObject != null)
{
StartCoroutine(RotateImage());
}

IEnumerator RotateImage()
{
float moveSpeed = 1f;
while(myObject.transform.rotation.y < 180)
{
myObject.transform.rotation = Quaternion.Slerp(myObject.transform.rotation, Quaternion.Euler(0, 180, 0), moveSpeed * Time.deltaTime);
yield return null;
}
myObject.transform.rotation = Quaternion.Euler(0, 180, 0);
yield return null;
}
``````

or like this

``````if (myObject != null)
{
StartCoroutine(RotateImage());
}

IEnumerator RotateImage()
{
float moveSpeed = 1f;
while(myObject.transform.rotation.y < 180)
{
myObject.transform.rotation = Quaternion.Lerp(myObject.transform.rotation, Quaternion.Euler(0, 180, 0), moveSpeed * Time.deltaTime);
yield return null;
}
myObject.transform.rotation = Quaternion.Euler(0, 180, 0);
yield return null;
}
``````