- Home /
Gyroscope behaving differently between Samsung and Google Pixel
I wanted to control the camera with the gyroscope of Unity and I saw the code on another post here on how to do that. But the behaviour is different between the Google Pixel and Samsung S7 I have to test the app. It seems that the same scene with the same code is flipped about 180 degrees along one of the axis.
using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;
public class GyroControl : MonoBehaviour {
private bool gyroEnabled;
private Gyroscope gyroscope;
private GameObject cameraContainer;
private Quaternion rotation;
void Start () {
cameraContainer = new GameObject ("Camera Container");
cameraContainer.transform.position = transform.position;
transform.SetParent (cameraContainer.transform);
Screen.sleepTimeout = SleepTimeout.NeverSleep;
gyroEnabled = EnableGyro ();
}
private bool EnableGyro() {
if (SystemInfo.supportsGyroscope) {
gyroscope = Input.gyro;
gyroscope.enabled = true;
cameraContainer.transform.rotation = Quaternion.Euler (90.0f, 0.0f, 0.0f);
rotation = new Quaternion (0, 0, 1, 0);
return true;
}
return false;
}
void Update () {
if (gyroEnabled) {
transform.localRotation = gyroscope.attitude * rotation;
}
}
}
Tell me if I am wrong, you ask just about the state after init right ?
I'm wondering what is different between the phones. They rotate differently, the models are opposite to each other when building the same app. Don't know if it's the value of the rotation or the quaternion euler of the camera container.
Just read somewhere that gyroscope values range might be different for different devices. In such case you would have to know such range and normalize 'i guess attitude' it before applying rotation to object / camera.
Your answer
![](https://koobas.hobune.stream/wayback/20220612181752im_/https://answers.unity.com/themes/thub/images/avi.jpg)