Okay guys i’ve tried pretty much all solutions I could find on the web and still couldn’t fix this problem, also tried some scripts found on the web to no avail. I can’t for the life of me figure this out
I need a gyroscope script to get my camera to rotate on 360° on an android device but I’m having some huge gimbal lock issues. At a certain angle, the camera will glitch and do a weird rotation. This lasts for some frames and then the rotation is ok, but the glitch is highly disturbing… Can someone help me with this ?
Heres my code :
using UnityEngine;
public class GyroCamera : MonoBehaviour
{
private bool gyroBool;
private Gyroscope gyro;
private Quaternion rotFix;
Quaternion quat;
Quaternion quatMap;
public void Start()
{
Transform currentParent = transform.parent;
GameObject camParent = new GameObject("GyroCamParent");
camParent.transform.position = transform.position;
transform.parent = camParent.transform;
gyroBool = SystemInfo.supportsGyroscope;
if (gyroBool)
{
gyro = Input.gyro;
gyro.enabled = true;
camParent.transform.eulerAngles = new Vector3(90, 180, 0);
rotFix = new Quaternion(0, 0, 1, 0);
}
}
public void Update()
{
if (gyroBool && this.gameObject.GetComponent<Camera>().enabled)
{
quatMap = gyro.attitude;
quat = gyro.attitude * rotFix;
transform.localRotation = quat;
}
}
}
I hope some good soul can help me on this… Thanks guys !