为了账号安全,请及时绑定邮箱和手机立即绑定

按下按键时 Unity 重置 Oculus 位置

按下按键时 Unity 重置 Oculus 位置

C#
HUH函数 2023-07-09 17:06:30
我正在尝试创建一个脚本,每当出于校准原因按下按键时,该脚本都会重置(到特定位置)HMD 和控制器位置。我对 Unity 很陌生,所以我所能弄清楚的就是如何获取关键输入。public class resetPosition : MonoBehaviour{    // Start is called before the first frame update    void Start()    {    }    // Update is called once per frame    void Update()    {        if (Input.GetKeyDown(KeyCode.Space))            Debug.Log("pressed");    }}
查看完整描述

1 回答

?
守着一只汪

TA贡献1872条经验 获得超3个赞

您不应该直接更改 VRCamera 的位置。


而是将父级添加GameObject到相机并通过例如更改该父级的位置(假设您的脚本已附加到相机)


public class ResetPosition : MonoBehaviour

{

    public Vector3 resetPosition;


    private void Awake()

    {

        // create a new object and make it parent of this object

        var parent = new GameObject("CameraParent").transform;


        transform.SetParent(parent);

    }


    // You should use LateUpdate

    // because afaik the oculus position is updated in the normal

    // Update so you are sure it is already done for this frame

    private void LateUpdate()

    {

        if (Input.GetKeyDown(KeyCode.Space))

        {

            Debug.Log("pressed");


            // reset parent objects position

            transform.parent.position = resetPosition - transform.position;

        }

    }

}


查看完整回答
反对 回复 2023-07-09
  • 1 回答
  • 0 关注
  • 123 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信