Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Physics hate: 270º != 270º - Please help

Discussion in 'Physics' started by Teku-Studios, Feb 10, 2015.

  1. Teku-Studios

    Teku-Studios

    Joined:
    Sep 29, 2012
    Posts:
    257
    I've been developing a game in Unity for almost 3 years and I'm still trying to understand how to deal with rotations. One very specific situation is breaking my code and I need help on how to fix that. Here's my case scenario:

    I have an object which can be rotated to absolute values (0 - 90 - 180 - 270), and I need to check that initial rotation before applying some other transformations. I do this:

    int angleZ = (int) m_spriteTransform.rotation.eulerAngles.z;

    if(angleZ == 270)
    Do some stuff;
    else if(angleZ > 180 && angleZ < 270)
    Do other stuff;

    I need to do that check for reasons that are not important now, but here's what happens. I'm forcing its rotation to be 270 degrees

    i
    nt angleX = 0;
    int angleY = 0;
    int angleZ = 270;


    m_spriteTransform.rotation = Quaternion.EulerAngles(angleX, angleY, angleZ);

    And there is NOTHING at all changing that object's rotation. Anything. However, when I do the first check, the code if(angleZ == 270) returns FALSE, and the code else if(angleZ > 180 && angleZ < 270) returns TRUE, which makes no goddam sense.

    I'm setting breakpoints and also a Debug.Log info log and, after checking both, angleZ returns 270, so I don't know what is happenning.


    How can I deal with this properly?
     
    Last edited: Feb 12, 2015
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
  3. Teku-Studios

    Teku-Studios

    Joined:
    Sep 29, 2012
    Posts:
    257
  4. Kavorka

    Kavorka

    Joined:
    Sep 15, 2012
    Posts:
    247
    Does this help?
    Code (CSharp):
    1. int angleZ = (int) m_spriteTransform.rotation.eulerAngles.z + .5f;
     
  5. Teku-Studios

    Teku-Studios

    Joined:
    Sep 29, 2012
    Posts:
    257
    Nope, but thanks for your help. I rearranged the code to work in a different way and now it is solved.