Input.gyro.attitude not working on newer Android devices

Hi guys,

I’ve written an app for viewing 360° panoramas. The app has a Google Cardboard mode, and a normal mode where you can rotate the camera either using touch input or using the phones/tablets gyroscope.
Now this app has been in the stores for a while now and everything was working fine.
Both in iOS and Android.
But recently more and more Android devices have been popping up, where my code for the camera rotation controlled by the gyroscope doesn’t work anymore.
The phones in question do have a gyroscope, and frustratingly the Google Cardboard mode works fine.
However Googles code is hidden in a dll, so I can’t see how they accomplish this.

Here’s a code snippet of the camera rotation code:

// current measurement:
Quaternion gyroMeasurement = Input.gyro.attitude;
gyroMeasurement = new Quaternion(-gyroMeasurement.x,-gyroMeasurement.z, -gyroMeasurement.y, gyroMeasurement.w);
gyroMeasurement = gyroMeasurement * Quaternion.Euler(90, 0, 0);
Vector3 euler = gyroMeasurement.eulerAngles;

// calculate the delta values between our current measurement and the first measurement. 
// Update: we only want the offset on the y-axis. The x-axis should be the current gyro measurement. 
Vector3 finalDeltaValues = new Vector3();
       
finalDeltaValues.y = euler.y  -m_initialGyroMeasurement.y;

// add the small delta values to the original orientation of the camera.
float finalEulerValueX = euler.x; 
float finalEulerValueY = m_currentEulerVec.y + finalDeltaValues.y;

// feed these values into a quaternion and then perform the movement.
if (bAnimated)
    StartCoroutine(RotateCameraAnimation(transform, transform.rotation, Quaternion.Euler(finalEulerValueX, finalEulerValueY, 0), 0.3f, false));
else
   transform.rotation = Quaternion.Euler(finalEulerValueX, finalEulerValueY, 0);

In Debug mode I can see that Input.gyro.attitude always returns 0,0,0,1 on these devices.
Can anyone point me in the right direction to get this working again?
Feel free to contact me if you need any more info.

Cheers,
Sebastian

Hello,
My development team was having a similar issue. We would set Input.gyro.enabled = true yet it would return false. I suggest downloading Gyrodroid in the Google Play store and click on Statistics - All Sensors. The phones that were giving me this issue all returned Gyroscope - NO meaning it doesn’t exist in my device. In our case we need the gyro specifically as opposed to accelerometer unfortunately.

hi, my systeminfo return support gyroscope =>true, but also return a attitude of (0,0,0,1), in fact,its return gyro.gravity with some diferent values, but attitude dont work, beside, u can see a dll with .net reflector windows app

@LK84
Hi LK84,

Yes in both cases.
If SystemInfo.supportGyroscope returns false I don’t even show the buttons to switch into Gyroscope mode or Google Cardboard mode.
But on some newer Android devices the SystemInfo.supportGyroscope returns true. → I show the buttons. Google Cardboard mode works fine but Input.gyro.attitude doesn’t return anything, thus rendering my Gyroscope mode useless (user remains stationary).