Search Unity

Why can't I get exactly 90deg rotation?

Discussion in 'Scripting' started by bitinn, Sep 28, 2016.

  1. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    I tried to rotation a quad. But unless I set it in Editor, I always get 89.981 instead of 90.

    I tried:

    Code (CSharp):
    1. transform.localRotation = Quaternion.Euler(90, 0, 0);
    2.  
    3. transform.localEulerAngles = new Vector3(90, 0, 0);
    Is there something between Euler and Quaternion conversion that I am not aware of?
     
  2. CloudKid

    CloudKid

    Joined:
    Dec 13, 2015
    Posts:
    207
    Do you need exactly 90? there should be no visible difference from 89.981 to 90...
    Your problem might come from lose of precision when using floats. This happens when you are doing computations with float, especially conversions between Euler and Quaternions. Also, the value that is displayed in inspector and that is received when requesting euler angles is not the actual rotation of the object. Unity uses only Quaternions to handle rotation. However, to be easier for the end user all the Quaternion data is converted to Eulerian space. So, there is no problem with the actual rotation, only with the data that you receive when requesting rotations.
     
  3. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    I am aware of floating point precision problem.

    If Euler to Quaternion conversion is already messing up floating point value (which, to be honest, should be in the 10^(-6) range, not a 10^(-2) difference), how should one avoid such problem?
     
  4. Aldrick

    Aldrick

    Joined:
    Feb 19, 2014
    Posts:
    64