我正在制作一个 360 视频播放器,相机位于球体的中心,我已经将陀螺仪安装到相机中,它可以正常工作,但是当我四处移动时,会出现奇怪的晃动,看起来像是即使手机静止,也会出现某种延迟。 屏幕方向锁定为横向。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gyro : MonoBehaviour {
private Gyroscope gyro;
private bool gyroSupported;
private Quaternion rotFix;
void Start()
{
gyroSupported = SystemInfo.supportsGyroscope;
GameObject camParent = new GameObject("camParent");
camParent.transform.position = transform.position;
transform.parent = camParent.transform;
if (gyroSupported)
{
gyro = Input.gyro;
gyro.enabled = true;
camParent.transform.rotation = Quaternion.Euler(90f, 180f, 0f);
rotFix = new Quaternion(0, 0, 1, 0);
}
}
void Update()
{
this.transform.Rotate(-Input.gyro.rotationRateUnbiased.x, -Input.gyro.rotationRateUnbiased.y, -Input.gyro.rotationRateUnbiased.z);
}
}
最佳答案
下面的代码应该可以解决这个问题:
void Update()
{
this.transform.Rotate (-Input.gyro.rotationRateUnbiased.x, -Input.gyro.rotationRateUnbiased.y, -Input.gyro.rotationRateUnbiased.z);
}
引用自here .
关于c# - 陀螺仪在移动时晃动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43945972/