c# - 陀螺仪在移动时晃动

标签 c# android unity-game-engine gyroscope

我正在制作一个 360 视频播放器,相机位于球体的中心,我已经将陀螺仪安装到相机中,它可以正常工作,但是当我四处移动时,会出现奇怪的晃动,看起来像是即使手机静止,也会出现某种延迟。 屏幕方向锁定为横向。

enter image description here

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/

相关文章:

c# - wpf:无法识别左键单击

c# - 用户控制选项卡

c# - 如何修复 "Pinvoke stack imbalance detected"错误

android - ListView 中 View 持有者模式与自定义 View 的区别

c# - Unity 中 invoke 或 ienumerator 是更好的方法吗?

c# - Unity中GameObject的引用脚本类

c# - Microsoft Azure 应用服务存储

java - 多线程的启动和加入顺序不同?

android - 什么时候用懒加载,什么时候不用?

unity-game-engine - 将玩家信息保存在外部文件中