SHARE
TWEET

kod

a guest May 20th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using InputTracking = UnityEngine.XR.InputTracking;
  6. using Node = UnityEngine.XR.XRNode;
  7.  
  8.  
  9. public class LocalPlayerControl : NetworkBehaviour
  10. {
  11.     public GameObject ovrCamRig;
  12.     public Transform leftHand;
  13.     public Transform rightHand;
  14.     public Camera leftEye;
  15.     public Camera rightEye;
  16.     Vector3 pos;
  17.  
  18.     void Start()
  19.     {
  20.         pos = transform.position;
  21.  
  22.     }
  23.  
  24.     void Update()
  25.     {
  26.         if(!isLocalPlayer)
  27.         {
  28.             Destroy(ovrCamRig);
  29.         }
  30.         else
  31.         {  
  32.             //take care of cam when player 2 joins
  33.  
  34.             if(leftEye.tag != "MainCamera")
  35.             {
  36.                 leftEye.tag = "MainCamera";
  37.                 leftEye.enabled = true;
  38.             }
  39.             if (rightEye.tag != "MainCamera")
  40.             {
  41.                 rightEye.tag = "MainCamera";
  42.                 rightEye.enabled = true;
  43.             }
  44.  
  45.             //take care of hand position tracking
  46.             leftHand.localRotation = InputTracking.GetLocalRotation(Node.LeftHand);
  47.             rightHand.localRotation = InputTracking.GetLocalRotation(Node.RightHand);
  48.             leftHand.localPosition = InputTracking.GetLocalPosition(Node.LeftHand);
  49.             rightHand.localPosition = InputTracking.GetLocalPosition(Node.RightHand);
  50.  
  51.             //handle position and rotation of player
  52.             Vector2 primaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
  53.  
  54.             if(primaryAxis.y > 0f)
  55.             {
  56.                 pos += (primaryAxis.y * transform.forward * Time.deltaTime);
  57.             }
  58.             if(primaryAxis.y < 0f)
  59.             {
  60.                 pos += (Mathf.Abs(primaryAxis.y) * -transform.forward * Time.deltaTime);
  61.             }
  62.             if (primaryAxis.x > 0f)
  63.             {
  64.                 pos += (primaryAxis.x * transform.right * Time.deltaTime);
  65.             }
  66.             if (primaryAxis.x < 0f)
  67.             {
  68.                 pos += (Mathf.Abs(primaryAxis.x) * -transform.right * Time.deltaTime);
  69.             }
  70.  
  71.             transform.position = pos;
  72.  
  73.             Vector3 euler = transform.rotation.eulerAngles;
  74.             Vector2 secondaryAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
  75.             euler.y += secondaryAxis.y;
  76.             transform.rotation = Quaternion.Euler(euler);
  77.             //maybe set local rotation too?
  78.             transform.localRotation = Quaternion.Euler(euler);
  79.  
  80.  
  81.  
  82.         }
  83.     }
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top