Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Problems with gyro camera rotation.

Discussion in 'AR/VR (XR) Discussion' started by MGlolenstine, Dec 4, 2018.

  1. MGlolenstine

    MGlolenstine

    Joined:
    Sep 1, 2014
    Posts:
    2
    Hey, this is my first post, please be gentle.

    I want to rotate camera in the game, just as I am moving the phone(Just like VR does it).

    for that I'm currently using this piece of code
    Code (CSharp):
    1. cam.transform.Rotate(-gyro.rotationRate[0], -gyro.rotationRate[1], gyro.rotationRate[2]);
    but it doesn't really do the job. When I try the app out via Unity Remote(this could actually be the problem), and if my phone was perfectly flat on the table, I fidget with it and return it back to the same position as it was in before, camera is still rotated and/tilted. It's just like I'm losing some of the information that the gyro should be sending.

    Is there something I'm doing wrong and/or would be better done with something else?

    Thanks!

    EDIT: Just tested... UnityRemote is not the problem.
     
    Last edited: Dec 4, 2018
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    7,816
    You're not doing anything wrong. It's just that what you want to do is pretty much impossible. VR doesn't do it without fancy extra hardware. AR does it only by finding (through some very deep and fancy algorithms) visual markers in the environment, and even with all the muscle of Apple or Google behind it, it still shifts/drifts sometimes. The gyros are just not precise enough to not accumulate error over time, and probably never will be.

    Depending on your goals, it's possible you could do somewhat better by using the compass rather than the gyro. But that too will only get you so far.
     
  3. MGlolenstine

    MGlolenstine

    Joined:
    Sep 1, 2014
    Posts:
    2
    Wait, so you're suggesting that I use compass for rotation around Y axis and accelerometer for everything else?

    Thanks for the reply!
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    7,816