Hi, being fairly new to unity, am using unity 5.4.0f3. I am working on a project which makes use of device gyroscope, if it exists, to give rotation to the main camera. I have tested the application on few devices, out of which Moto G 4th generation phone is the one, that I came across as of now, which even if has a gyroscope on it, gives zero values for Input.gyro.attitude. It is a device with 6.0.1 android and as mentioned ‘Unity Issue Tracker - Input.gyro.attitude doesn't output data from OrientationSensor’, there was one bug reported in unity about issues with getting gyro attitude values in newer devices(Android 6 or later)
I tried below code to debug the gyro values in phones:
using UnityEngine;
using System.Collections;
public class gyro : MonoBehaviour {
Gyroscope gyr;
// Use this for initialization
void Start () {
gyr = Input.gyro;
if (SystemInfo.supportsGyroscope)
{
gyr.enabled = true;
Debug.LogWarning("Gyro Enabled");
}
}
// Update is called once per frame
void Update () {
Debug.Log(gyr.attitude);
}
}
Is the issue really solved or am I doing anything wrong here? Is there a workaround that I should be looking at for newer devices like this? Any help or suggestion would be great.
@sanketkale The Moto 4th generation phones and lower generation(i am not that sure about the lower gen phones, but sure about the 4th gens, since I have a moto G4 plus) do not have a compass or magnetometer, which is what Input.gyro.attitude uses.
If you want to use the gyroscope for AR, you need the compass/magnetometer, else the accelerometer will have to do.
There are some obvious trade-offs between the gyroscope and the accelerometer, but then, it’s a necessity. @yuk27 how did the code work if the phone doesn’t have a compass/magnetometer? Do let me know, i would love to know.
Thanks! :D, sorry if the answer is wrong or something, i just posted my own experience. If someone has a change, do let me know, bye <3