# Quaternion not giving correct value back. What am I doing wrong here?

Right so I made a quaternion and assigned it a value but it reports back the wrong value.

Here is the relevant code...

Quaternion LeftTurnLimit = Quaternion.identity;
float test = 0.1f;

LeftTurnLimit = Quaternion.Euler(test, 0, 0);
Debug.Log(LeftTurnLimit);


Expected result: (0.1, 0, 0) / (x, y, z) Result: (0.0, 0.0, 0.0, 1.0) / (x, y, z, w)

So what am I doing wrong here?

• (1) Your expected value is incorrect; and (2) you are not displaying enough decimals in your actual result, as you will need to show 4 (probably) to get sufficient precision for this test. Repeat three times: "Quaternions are NOT vectors.". Then repeat three more times "Degrees are 57 times smaller than radians." Apr 23 '16 at 5:10
• @PieterGeerkens Perhaps I was asking for the wrong thing then. I think the majority of quaternion related problems stem from mistakenly conflating vectors with quaternions.
– Sie
Apr 23 '16 at 5:20

Rounding.

If you attach the debugger and look at the values of your quaternion:

You'll see that the values are just too small to be displayed with one tenth precision, as the debug value is displayed.

You can confirm this by looking at:

Debug.Log(LeftTurnLimit.eulerAngles);


This will output the initial value you put in : 0.1, 0, 0

To address the differences in what you expected, vs what you got out.

Quaternions and euler angles are different, but with a similar goal. They're different ways of representing rotations in 3D space. They may have some commonly named components, but they store different information, because the process for converting the data stored into a rotation are different. If you want specifics about how each of them work, you should research the one you're interested in. You can ask specifically about anything you don't understand in a new question, after researching.

• This is not a rounding error, you cannot directly compare quaternions to euler angles. They are two different things. Apr 23 '16 at 8:56
• @S.TarıkÇetin I'm aware they're different things. Since OP gave expected answer in x,y,z, I thought they understood as well, it's been revealed since then that's not the case.
– House
Apr 23 '16 at 16:28
• @Byte56 What exactly is the difference? If you could include it in the answer I think the question would be more complete.
– Sie
Apr 23 '16 at 16:40

Quaternions are different than Euler angles; Euler angles has 3 components (x, y, z) while Quaternions has 4 (x, y, z, w). If you want your result in Euler angles, use following code piece:

Quaternion LeftTurnLimit = Quaternion.identity;
float test = 0.1f;

LeftTurnLimit = Quaternion.Euler(test, 0, 0);
var LeftTurnLimitEuler = LeftTurnLimit.eulerAngles;
Debug.Log(LeftTurnLimitEuler);


Here is the related API page: http://docs.unity3d.com/ScriptReference/Quaternion-eulerAngles.html