Skip to content

Instantly share code, notes, and snippets.

@nkjzm
Created July 7, 2018 06:20
Show Gist options
  • Save nkjzm/f9f8e1922b4fdb7f362568913ef43c6b to your computer and use it in GitHub Desktop.
Save nkjzm/f9f8e1922b4fdb7f362568913ef43c6b to your computer and use it in GitHub Desktop.
【Unity】VRカメラのポジショントラッキングを無効化する ref: https://qiita.com/splas_boomerang/items/d5cb371a99b0c7e956c2
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