Hi all. I’ve been trying for the past few days to implement a simple(!) piece of code which would allow me to control the horizontal rotation of a camera using the gyroscope of my android device. It is a first person game, in which the player should be able to ‘look around’ 360 degrees along the horizontal axis. Imagine sitting in an office chair with the device held out in front of you, then spinning round 360 degrees. As you spin, so should the camera in the game. Here’s the closest I’ve come:
using UnityEngine;
using System.Collections;
public class GyroRotate : MonoBehaviour {
void Start ()
{
Input.gyro.enabled = true;
}
void Update ()
{
var x = Input.gyro.rotationRateUnbiased.x;
transform.eulerAngles = new Vector3 (x, 0, 0);
}
}
This script is attached to an empty game object with the main camera as a child. The problem with this is the camera only rotates a little, then always snaps back to its original position. Any help or advice would be hugely appreciated - I’m quite new to all of this!