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, 0f, -90f);
rot = new Quaternion(0, 0, 1, 0);
return true;
}
return false;
}
private void Update()
{
if (gyroEnabled)
{
transform.localRotation = gyro.attitude * rot;
}
}
}
i have a game that build with using gyroscope but the gyroscope use world rotation i don't want that i want whenever i start the game and my phone direction anywhere it makes it the start rotation , i mean if i start the game i will use the same camera rotation and move right and left by the gyro scope value .
i tried this :
private Quaternion initialRot;
/
private bool EnableGyro()
{
if (SystemInfo.supportsGyroscope)
{
gyro = Input.gyro;
gyro.enabled = true;
initialRot = gyro.attitude;
cameraContainer.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
return true;
}
return false;
}
/
private void Update()
{
if (gyroEnabled)
{
transform.localRotation = gyro.attitude * Quaternion.Inverse(initialRot);
}
}
in the end i want to make the gyro value build above the current phone direciotn