- Home /
Gyro attitude wrong data on ios
Hello!
I am working with gyro attitude to code a 360 video look around feature.
I am using this code: (from here: https://www.youtube.com/watch?v=P5JxTfCAOXo). From what I have been reading this is the standard way of doing this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GyroControl : MonoBehaviour
{
private bool gyroEnabled;
private Gyroscope gyro;
private GameObject cameraContainer;
private Quaternion rot;
private void Start()
{
cameraContainer = new GameObject ("Camera Container");
cameraContainer.transform.position = transform.position;
transform.SetParent (cameraContainer.transform);
gyroEnabled = EnableGyro ();
}
private bool EnableGyro()
{
if (SystemInfo.supportsGyroscope)
{
gyro = Input.gyro;
gyro.enabled = true;
cameraContainer.transform.rotation = Quaternion.Euler (90f, 90f, 0f);
rot = new Quaternion (0, 0, 1, 0);
return true;
}
return false;
}
private void Update()
{
if (gyroEnabled)
{
transform.localRotation = gyro.attitude * rot;
}
}
}
This works very well for Android in a consistent way.
However on iOS I am getting very weird results: I get consistent bad results, which change everytime I kill the app and launch again. ie: I launch the app, and I get an 90degree error, everytime i launch my 360 video in the app I get the same error, but if I kill the app and launch it again, I get a different error.
I am very puzzled with this, I have logged out the gyro attitude and it seems to be completely off on ios, but I get very different results when restarting the app (different errors, but consintet through the app, only changing when restarting the app). I have also tried enabling the gyro in advance, and give it time before starting the 360 video code.
What am I missing?
If anyone has any advice on this, it would be highly appreciated. Thanks a lot!!