Created
July 7, 2018 06:20
-
-
Save nkjzm/f9f8e1922b4fdb7f362568913ef43c6b to your computer and use it in GitHub Desktop.
【Unity】VRカメラのポジショントラッキングを無効化する ref: https://qiita.com/splas_boomerang/items/d5cb371a99b0c7e956c2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CameraController : MonoBehaviour | |
{ | |
Vector3 basePos = Vector3.zero; | |
void Start() | |
{ | |
basePos = transform.position; | |
} | |
void Update() | |
{ | |
// VR.InputTracking から hmd の位置を取得 | |
var trackingPos = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye); | |
var scale = transform.localScale; | |
trackingPos = new Vector3( | |
trackingPos.x * scale.x, | |
trackingPos.y * scale.y, | |
trackingPos.z * scale.z | |
); | |
// 回転 | |
trackingPos = transform.rotation * trackingPos; | |
// 固定したい位置から hmd の位置を | |
// 差し引いて実質 hmd の移動を無効化する | |
transform.position = basePos - trackingPos; | |
// 子のカメラの座標がbasePosと同じ値になるかを確認する | |
// Debug.Log(transform.GetChild(0).position); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment