Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using InputTracking = UnityEngine.XR.InputTracking;
- using Node = UnityEngine.XR.XRNode;
- public class LocalPlayerControl : NetworkBehaviour
- {
- public GameObject ovrCamRig;
- public Transform leftHand;
- public Transform rightHand;
- public Camera leftEye;
- public Camera rightEye;
- Vector3 pos;
- void Start()
- {
- pos = transform.position;
- }
- void Update()
- {
- if(!isLocalPlayer)
- {
- Destroy(ovrCamRig);
- }
- else
- {
- //take care of cam when player 2 joins
- if(leftEye.tag != "MainCamera")
- {
- leftEye.tag = "MainCamera";
- leftEye.enabled = true;
- }
- if (rightEye.tag != "MainCamera")
- {
- rightEye.tag = "MainCamera";
- rightEye.enabled = true;
- }
- //take care of hand position tracking
- leftHand.localRotation = InputTracking.GetLocalRotation(Node.LeftHand);
- rightHand.localRotation = InputTracking.GetLocalRotation(Node.RightHand);
- leftHand.localPosition = InputTracking.GetLocalPosition(Node.LeftHand);
- rightHand.localPosition = InputTracking.GetLocalPosition(Node.RightHand);
- //handle position and rotation of player
- Vector2 primaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
- if(primaryAxis.y > 0f)
- {
- pos += (primaryAxis.y * transform.forward * Time.deltaTime);
- }
- if(primaryAxis.y < 0f)
- {
- pos += (Mathf.Abs(primaryAxis.y) * -transform.forward * Time.deltaTime);
- }
- if (primaryAxis.x > 0f)
- {
- pos += (primaryAxis.x * transform.right * Time.deltaTime);
- }
- if (primaryAxis.x < 0f)
- {
- pos += (Mathf.Abs(primaryAxis.x) * -transform.right * Time.deltaTime);
- }
- transform.position = pos;
- Vector3 euler = transform.rotation.eulerAngles;
- Vector2 secondaryAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
- euler.y += secondaryAxis.y;
- transform.rotation = Quaternion.Euler(euler);
- //maybe set local rotation too?
- transform.localRotation = Quaternion.Euler(euler);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement