- Home /

# Problem in Euler angles

Good afternoon. I have the following problem. For object rotation I use Quaternion.Euler with value of the appropriate angles. As I understood in a number of experiments, in Unity there is a certain problem for angles of the close to 90 degrees in case of rotation on a y axis. For example, following code:

```
void start() {
this.transform.rotation = Quaternion.Euler(88, 0, 0);
Debug.log("myangles=" + this.transform.eulerangles.x);
}
```

In my debug, I see: "myangles=90". After several experiments, it is possible to tell with confidence that the such happens to value of an angle from 87 degrees. That is to 87 degrees value in logs matches what I set as Quaternion.Euler, but after 87 for some reason there is a rounding to 90 degrees. Prompt please, whether it is possible to make so that in Unity the correct values for the angles close to 90 degrees were put. (I sometimes need to rotate the camera to value 90, and then smoothly to transfer it to value 0 without involvement of the user)

**Answer** by robertbu
·
Dec 12, 2013 at 06:54 PM

The behavior is strange to me. Even though the Inspector reports 90, an object is clearly being rotated to 88 degrees. Regardless of this issue, it is a bad idea to read from eulerAngles if you can avoid it. There are situations where Unity changes the euler representation of the current physical rotation. So a work around would be to keep your own Vector3. Example:

```
Vector3 myEuler;
void Start() {
myEuler = new Vector3(88,0,0);
transform.eulerAngles = myEuler;
Debug.Log("my X rotation: " + myEuler.x);
}
```

I also tried such code, but the same result. There is a possibility of that I am a bug of the Unity version in which I work (version 4.1.2 and while I am not going to transfer to later). So this mismatch remains, but I try to avoid it in process of opportunities.

Are you sure your code is not reading eulerAngles? This code works by treating eulerAngles as write-only and never reading the values back. The value in the inspector will still be 90 degrees, but your Debug.Log() and physical rotation will all be 88.0.

You are probably right, I applied such code yesterday and was guided by value in the Inspector, instead of in logs. Then it turns out that value shown in the Inspector for this case not correct. Is it valid so?

I ran the code and verified that the physical rotation is correct (i.e. only 88 degrees), and the angle reported from myEuler is also 88.0. The inspector will still report 90, but since you are not using eulerAngles, that won't impact your app.

I was guided by value in the Inspector, probably in it there was my error. Then I have a question: how to learn value of physical rotation? (how to receive these 88 degrees, without using additional variables? ) And many thanks for given help.

**Answer** by TehJustice
·
Dec 12, 2013 at 07:30 PM

It's a known issue with conversion from Quaternion to euler angles. Just use the Quaternion rotation functions and you'll be fine.

`transform.rotation = Quaternion.Euler(88, 0, 0);`

will give you a rotation of 88.

`transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 0, 0), Time.time * speed);`

will rotate you back to zero

Strange that it will turn on this angle (88), after all in the inspector it displays 90. And even in this case, to control my turning angle of the camera, it is necessary to enter float variable for this angle. Whether what in the Inspector it shows the wrong value is possible? For the help of the slerp function thanks, and that I used mathf.lerpangles for the angle necessary to me.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Rotation Jumping values (0 to 180) 1 Answer

Camera viewport transformation from one world to the rotated world. 1 Answer

c# modify only one axis of a quaternion 2 Answers

How to get Angle float of specific axis.(Turret clamping related). 2 Answers

How do you smoothly transition/Lerp into a new rotation? 2 Answers