Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to calibrate the mobile gyroscope ?

Discussion in 'AR/VR (XR) Discussion' started by Deleted User, Jul 5, 2020.

  1. Deleted User

    Deleted User

    Guest

    Hi,

    I want to use my mobile phone to view 360 pictures. Here is my problem :
    • When I make complex movements the camera is disturbed...
    • When the scene starts, the camera does not initialize in the right direction...

    I make tests with this script that I attach to the camera :

    gyro01.cs
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class gyro01 : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.         Input.gyro.enabled = true;
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.         this.transform.Rotate (-Input.gyro.rotationRateUnbiased.x, -Input.gyro.rotationRateUnbiased.y, 0);
    17.     }
    18. }

    The script "work pretty well" when I use my mobile facing a vertical plane in irl and on the x and y axis

    Initialization vertical plane | only x and y axis | gyro01.cs
    gyro01.gif

    Problem number one :
    If I rotate on the x-axis when my mobile is not perfectly aligned with the y-axis (and conversely), then the camera position is disturbed...

    Initialization vertical plane | x, y and z axis | gyro01.cs
    gyro01_diagonal.gif

    Problem number two :
    In this case, when the scene starts the mobile is lying on a horizontal plane, and yet the camera is looking straight ahead. It should be looking down...

    Initialization horizontal plane | x axis | gyro01.cs
    gyro01_init.gif

    Thank you for your help ! :)
     
    Last edited by a moderator: Jul 6, 2020