我想让陀螺仪只改变对象的x轴和y轴。有单轴和三轴的代码(主要使用),但我找不到任何关于两轴的代码,也无法自己完成。
在应用前重置z轴或其他轴
private Vector3 startEulerAngles;
private Vector3 startGyroAttitudeToEuler;
private void Start()
{
Input.gyro.enabled = true;
startEulerAngles = transform.eulerAngles;
startGyroAttitudeToEuler = Input.gyro.attitude.eulerAngles;
}
private void Update()
{
Vector3 deltaEulerAngles = Input.gyro.attitude.eulerAngles - startGyroAttitudeToEuler;
// Z-axis reset, so it won't be applied.
deltaEulerAngles.z = 0.0f;
transform.eulerAngles = startEulerAngles - deltaEulerAngles;
}