[BUG] 4.10.1 Wrong value with float

Hi ,

I’m working on camera movement for my character since 3 week and i always have issue with rotation value …

So today i decided to redo the entire code and i found that UE4 give me wrong value .

Explanation :

On begin play i get the rotation of my character :
(i call a function but i show what it does few lines later don’t worry )

Then i check this rotation and depending of the value i set it to 0.0 , 90.0, 180.0, or 270.0 :

After that i set a rotator variable to store this rotation (i use this rotation as a default rotation ):

Then i call a function i’ve made to be sure that my rotation (on yaw) is between 0 and 360 to get rid of negative value :


(what the function do : )

I set 4 rotator variable with 4 different value (for the 4 angles : 0 , 90 , 180 , 270) :
(i use collapsed node to get some space )
(as you can see i set the result in another rotator variable to use it later and dont risk to alterate the first one (char default clamp rot …))

Inside the collapsed node :

Then i set the world rotation of my mesh (my character mesh ) with the value (Default Rot … ) :

After that i have a piece of code who basically set the right rotation when i press the right key :

every tick (with a delay to avoid spam ) i print the value of the rotation of my mesh (world Rot ) and the value of the backward variable (charRotBW ) :

The result in play mode :
(the mesh world rotation is blue and the backward value is orange )

As you can see the actual mesh world Rotation is 0.0 (no problem ) and the backward world rotation is at 180.0 (here again no problem )
But look at this :

You see ? i have a variable with a yaw value of 180 , and when i set the world rotation of my mesh with this variable the value go from 180.0 to -179.9 … WTF !!? why 179.9 ? and why negative value ?

so yeah i’m done with it , i’ve almost lost 3 week of work and i don’t understand the value change .

all idea are welcome , if you need more info ask me :slight_smile:

hope you guys can figure it out and thanks for your help and for taking your time to read me .

merry christmas and happy new year ! :slight_smile:

I can tell you why it happens, but I’m not good enough at math to tell you how to fix it. :slight_smile: It’s gimbal lock. Gimbal lock - Wikipedia Euler (gimbal lock) Explained - YouTube

And it’s changing to 179.999985 because of floating point errors. Nothing really to worry about there.

On the other hand, your code to round the rotation to 90° is excessive, just do this or use the “Snap To Grid (float)” node.

Hi Ross ,

Thank you a lot for your answer ! i now understand why Unity is using Quaternion :wink:

I’ll try the use of Snap To grid and this afternoon and came back with the result :slight_smile: hope it work and again : thank you for your help !