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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    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



    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 :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    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.     }
    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

    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

    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

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