Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [System.Serializable]
  6.  
  7. public class VRMap
  8. {
  9. public Transform vrTarget;
  10. public Transform rigTarget;
  11. public Vector3 trackingPositionOffset;
  12. public Vector3 trackingRotationOffset;
  13.  
  14. public void Map()
  15. {
  16. rigTarget.position = vrTarget.TransformPoint(trackingPositionOffset);
  17. rigTarget.rotation = vrTarget.rotation * Quaternion.Euler(trackingRotationOffset);
  18. }
  19. }
  20.  
  21. public class VRRIG : MonoBehaviour
  22. {
  23. public VRMap head;
  24. public VRMap leftHand;
  25. public VRMap rightHand;
  26.  
  27. public Transform headConstraint;
  28. private Vector3 headBodyOffest;
  29.  
  30. // Start is called before the first frame update
  31. void Start()
  32. {
  33. headBodyOffest = transform.position - headConstraint.position;
  34. }
  35.  
  36. // Update is called once per frame
  37. void LateUpdate()
  38. {
  39. transform.position = headConstraint.position + headBodyOffest;
  40. transform.forward = Vector3.ProjectOnPlane(headConstraint.up,Vector3.up).normalized;
  41.  
  42. head.Map();
  43. leftHand.Map();
  44. rightHand.Map();
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement