亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

按下按鍵時 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條經驗 獲得超4個贊

您不應該直接更改 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 關注
  • 208 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號