Search Unity

Gyroscope is returning zeros

Discussion in 'Scripting' started by Ashcastillo007, Jun 28, 2020.

  1. Ashcastillo007

    Ashcastillo007

    Joined:
    Dec 13, 2014
    Posts:
    1
    Hello everyone, i need your help to configure the gyroscope... I got this script, that works in other project that I built in Unity 2019 version... Now I use Unity 2020.2 and Input.gyro.attitude is returning me (0,0,0,0)... I thought is a configuration thing, because in Unity 2019 I remember made some player settings to made it work and in Unity 2020.2 the player settings are different and I don't know how to setup now to make it work... O maybe is my code, what do you think?

    Code (CSharp):
    1. private bool gyroEnable;
    2.     private Gyroscope gyro;
    3.     private Quaternion rot;
    4.     // Use this for initialization
    5.     private void Start () {
    6.         gyroEnable = EnableGyro();
    7.     }
    8.    
    9.     private bool EnableGyro(){
    10.         if(SystemInfo.supportsGyroscope){
    11.             gyro = Input.gyro;
    12.             gyro.enabled = true;
    13.             rot = new Quaternion(0,0,1,0);
    14.             return true;
    15.         }
    16.         return false;
    17.     }
    18.     // Update is called once per frame
    19.     private void Update () {
    20.         if(gyroEnable){
    21.             this.transform.localRotation = gyro.attitude * rot;
    22.         }
    23.     }
    24.  
    25.     private void OnGUI(){
    26.         GUI.Label(new Rect(10, 10, 500, 100),Input.gyro.attitude.ToString("F4")+Input.gyro.enabled.ToString());
    27.     }
     
    alphabeta314 likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    First stop should be to make a new blank 2020 project and work through the documentation Unity provides for Gyro input.
     
  3. unity_0t79gHUIu1X9ug

    unity_0t79gHUIu1X9ug

    Joined:
    May 24, 2020
    Posts:
    2
    That is also happening to me. My device is a Moto G8 with both Gyroscope and Accelerometer. It has no Magnetometer though. Input.gyro.attitude is always (0, 0, 0);
    I can use Input.gyro.rotationRate[Unbiased] methods but they don't work as a substitute for Input.gyro.attitude. 3D websites and google cardboard works so, it is likely a bug on Unity.
     
  4. julian-perso

    julian-perso

    Joined:
    Oct 30, 2012
    Posts:
    5
    hi.
    i have the same issue with my samsng tab s6 lite.
    I have the accelerometer and the gyro enabled. this tab has no magnetometer.
    gyro.attitude always return (0,0,0).
    i tried the same project on my galaxy s8 and Attitude isn't (0,0,0).

    Is it a normal behaviour of Unity?

    version : unity 2019.2.15f1
    galaxy tab s6 lite : SM-P610
    Android 10

    thanks a lot
     
  5. linh60bpm

    linh60bpm

    Joined:
    Oct 13, 2018
    Posts:
    8
    Same issue
    Unity 2020.2.1f1

    the Input.gyro work fine with unity editor and unity remote 5 app
    But after building apk fine, it always return (0,0,0)
     
  6. andre_unity106

    andre_unity106

    Joined:
    Aug 6, 2021
    Posts:
    1
    same here. after do build and run, the input.acceleration always return 0, 0, 0.
    tried many things, none works.
     
  7. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Samsung A71, Unity 2021.3.8f1, same zeroes, SystemInfo.supportsGyroscope return true, AR Foundation works too
     
  8. unity_393CC71ED135A28145A7

    unity_393CC71ED135A28145A7

    Joined:
    Apr 9, 2022
    Posts:
    2
    Are you sure you enabled the gyro?

    Input.gyro.enabled = true;