- Home /
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
Am I missing something here? How come nobody has answered or commented on this question?!? Not even with a follow up question.
does SystemInfo.supportsGyroscope
returns true on those devices? did you set Input.gyro.enabled = true
?
Answer by fake-love · Dec 03, 2016 at 07:41 AM
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.
Ok, thanks for the suggestion. I'll test that on the devices which were giving us problems...
Answer by Monstermash28425R1 · Jul 17, 2019 at 02:59 PM
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
Answer by Ashiash · Nov 16, 2016 at 10:10 AM
@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).
Your answer
Follow this Question
Related Questions
UNITY 3D - Set the start positon of the gyroscope to initial phone position 1 Answer
Android Gyroscope inaccuracy problems. 1 Answer
Clamp gyro rotation 0 Answers
Android: how do i make the rotation of my player follow the rotation of my phone 1 Answer
Input.gyro.attitude returns zero values when tested with Moto G 4th generation device 2 Answers