Advertisement
Guest User

Untitled

a guest
May 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using UnityEngine;
  2. using VRTK;
  3. using UnityEngine.XR;
  4.  
  5. public class CenterPlayspace : MonoBehaviour
  6. {
  7. public KeyCode ResetKey;
  8. public XRNode node;
  9.  
  10. private Vector3 hmdOffset;
  11. private VRTK_SDKManager manager;
  12.  
  13. void Start()
  14. {
  15. manager = FindObjectOfType<VRTK_SDKManager>();
  16. }
  17.  
  18. public void Center(){
  19. Vector3 headsetPosition = InputTracking.GetLocalPosition(node);
  20.  
  21. hmdOffset = new Vector3(
  22. headsetPosition.x,
  23. 0,
  24. headsetPosition.z
  25. );
  26.  
  27. manager.transform.position = transform.position - hmdOffset;
  28. }
  29.  
  30. private void OnDrawGizmosSelected()
  31. {
  32. Gizmos.color = Color.yellow;
  33. Gizmos.DrawWireCube(transform.position, new Vector3(4, 0.01f, 4));
  34. }
  35. private void Update()
  36. {
  37. if(Input.GetKeyDown(ResetKey)){
  38. Center();
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement