Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using VRTK;
- using UnityEngine.XR;
- public class CenterPlayspace : MonoBehaviour
- {
- public KeyCode ResetKey;
- public XRNode node;
- private Vector3 hmdOffset;
- private VRTK_SDKManager manager;
- void Start()
- {
- manager = FindObjectOfType<VRTK_SDKManager>();
- }
- public void Center(){
- Vector3 headsetPosition = InputTracking.GetLocalPosition(node);
- hmdOffset = new Vector3(
- headsetPosition.x,
- 0,
- headsetPosition.z
- );
- manager.transform.position = transform.position - hmdOffset;
- }
- private void OnDrawGizmosSelected()
- {
- Gizmos.color = Color.yellow;
- Gizmos.DrawWireCube(transform.position, new Vector3(4, 0.01f, 4));
- }
- private void Update()
- {
- if(Input.GetKeyDown(ResetKey)){
- Center();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement