Search Unity

how to flip x axis for rotation on gameobject

Discussion in 'Editor & General Support' started by DoggyBoggy, Jun 2, 2020.

  1. DoggyBoggy

    DoggyBoggy

    Joined:
    Jan 19, 2018
    Posts:
    20
    So I have a gyroscope constantly feeding values into unity to update a gameobjects rotation, only problem is that the sensors input of +x is unity's version of -x.

    Its giving me the values in forms of quaternions so I cant edit the direct values there unlike flipping the yaw in yaw pitch and roll euler angles, and since the values are constantly updating I cant make the x angle negative. I tried re-orienting the gameobject but when the x gets un-flipped then the y gets flipped instead. Only solution I could think of is flipping the x-axis in unity, but I dont know how to do that. Is this possible? And if not what else can I do?

    Any input is appreciated. Thanks! =)
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    I know it's usually a big no-no to touch Quaternion values directly but I believe this will do what you need (I'm interpreting what you need as "mirroring the rotation on the X axis". Let me know if it's something different you're looking for...)
    Code (CSharp):
    1. public static Quaternion MirrorOnXAxis(Quaternion q) {
    2.     q.y = -q.y;
    3.     q.z = -q.z;
    4.     return q;
    5. }
    Just remember this doesn't modify the Quaternion you pass in, it returns a new copy with the "fixed" x axis.
     
  3. DoggyBoggy

    DoggyBoggy

    Joined:
    Jan 19, 2018
    Posts:
    20
    well, that didnt work at first and I had the same problem, but i tinkered with the values of the quaternion so it was -z and -w, and that fixed it, but now the rotation on the z-axis is flipped.... Quaternions confuse me xD
     
    Last edited: Jun 2, 2020