# Rotating transform more than 180 degrees

Hi, I was wondering why my transform won’t keep rotating after 180 degrees. The rotation must be set and not something like Transform.Rotate due to the circumstances in my game.

Here is the code:
using UnityEngine;
using System.Collections;

``````public class Test : MonoBehaviour {

public float speed = 10;
public float time = 0.25f;

void Start () {

StartCoroutine("Wait");

}

void Rotate () {

Vector3 rot = transform.rotation.eulerAngles;
rot += new Vector3(speed, 0, 0);
transform.rotation = Quaternion.Euler(rot);
StartCoroutine("Wait");

}

IEnumerator Wait (){

yield return new WaitForSeconds (time);
Rotate ();

}
}
``````

Here is the result:

I know this is four years old, but for posterity.

Converting from euler angle to quaternion and back won’t always get you what you started with, since there’s more than one way to represent a rotation with euler angles (well, with quaternions too). When I tested this code, it actually wouldn’t rotate more than one step past 90 degrees. After setting `rot` to `(100, 0, 0)`, storing it as a quaternion and pulling it back into an euler representation, it turns out to be `(80, 180, 180)`, and when you add 10 degrees to the x component of that, you move backward. Unity stores the quaternion representation and just gives the euler representation when it’s asked for. In general, euler angles should only be used for humans to input and read rotations/orientations.

I don’t understand why Transform.Rotate won’t work for you, but if you must avoid it, you might try storing the euler representation as a class variable to ensure it stays as expected. The downside here is that if you’re rotating around multiple axes, you might also get unexpected results because euler rotations mean rotations around specific axes in a particular order. If you’re just doing one axis for a given object, you should be fine, though.

Work Variant will be

``````void Rotate()
{
Quaternion deltaQuaternionRot = Quaternion.AngleAxis(speed, Vector3.right);
transform.rotation = transform.rotation * deltaQuaternionRot;
StartCoroutine("Wait");
}
``````

I’m no big specialist in Rotation in Unity, but:

1. Rotation in Unity based on Quaternion mathematics where “rotation” = “Quaternion * Quaternion”;
2. the `rot += new Vector3(speed, 0, 0);` is wrong because you simply summarize two Vectors (Vector3), that `rot = transform.rotation.eulerAngles` doesn’t matter, because Vector3 is just a container for storing three unrelated numbers

P.S> `Quaternion.Euler(new Vector3(100, 0, 0)) == Quaternion.Euler(new Vector3(80,180, 180))` but `(Quaternion.Euler(new Vector3(100, 0, 0))).eulerAngles == new Vector3(80,180, 180)`. This is the specificity of the Quaternion to Euler conversion algorithm. ( not only Unity).
I saw recommendation "Be careful with Get “Quaternion.eulerAngles()”