Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Shared Player and motion Controller positions

Discussion in 'AR/VR (XR) Discussion' started by JD_FVTC, Nov 8, 2018.

  1. JD_FVTC

    JD_FVTC

    Joined:
    Oct 20, 2017
    Posts:
    10
    Im attempting to created a shared scene where i can see other peoples position & rotation Along with controller position and rotation.

    I have a player prefab with a head and two hands. I should see the remote players head and controllers as they move around.

    I want to see my hands prefab over the top of my own controllers too.

    The player prefab follows the mixed reality camera parent correctly.
    Any ides what I'm doing wrong here?

    Code (CSharp):
    1. [SyncVar]
    2.     private Vector3 localPosition;
    3.     [SyncVar]
    4.     private Quaternion localRotation;
    5.     [SyncVar]
    6.     private Vector3 remoteRightControllerPostion;
    7.     [SyncVar]
    8.     private Vector3 remoteLeftControllerPostion;
    9.     [SyncVar]
    10.     private Quaternion remoteRightControllerRotation;
    11.     [SyncVar]
    12.     private Quaternion remoteLeftControllerRotation;
    13.  
    14.  
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.  
    20.         if (!isLocalPlayer)
    21.         {
    22.             rightHand.transform.localRotation = remoteRightControllerRotation;
    23.             leftHand.transform.localRotation = remoteLeftControllerRotation;
    24.             rightHand.transform.localPosition = remoteRightControllerPostion;
    25.             leftHand.transform.localPosition = remoteLeftControllerPostion;
    26.             return;
    27.         }
    28.  
    29.         remoteLeftControllerRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.LeftHand);
    30.         remoteRightControllerRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.RightHand);
    31.  
    32.         remoteRightControllerPostion = transform.TransformPoint(UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.RightHand));
    33.         remoteLeftControllerPostion = transform.TransformPoint(UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.LeftHand));
    34.  
    35.         rightHand.transform.rotation = remoteRightControllerRotation;
    36.         leftHand.transform.rotation = remoteLeftControllerRotation;
    37.         rightHand.transform.position = remoteRightControllerPostion;
    38.         leftHand.transform.position = remoteLeftControllerPostion;
    39.  
    40.         head.transform.rotation = CameraCache.Main.transform.rotation;
    41.         transform.position = CameraCache.Main.transform.position;
    42.         CmdTransform(CameraCache.Main.transform.position, CameraCache.Main.transform.rotation,  leftHand.transform.rotation, rightHand.transform.rotation, rightHand.transform.localPosition, leftHand.transform.localPosition);
    43.     }
    44.  
    45.  
    46.     /// Sets the localPosition and localRotation on clients.
    47.     /// </summary>
    48.     /// <param name="postion">the localPosition to set</param>
    49.     /// <param name="rotation">the localRotation to set</param>
    50.     [Command(channel = 1)]
    51.     public void CmdTransform(Vector3 postion, Quaternion rotation, Quaternion rightHandRotation, Quaternion leftHandRotation, Vector3 rightControllerPostion, Vector3 leftControllerPostion)
    52.     {
    53.  
    54.         localPosition = postion;
    55.         localRotation = rotation;
    56.         remoteRightControllerRotation = rightHandRotation;
    57.         remoteLeftControllerRotation = leftHandRotation;
    58.         remoteLeftControllerPostion = leftControllerPostion;
    59.         remoteRightControllerPostion = rightControllerPostion;
    60.     }
    61. }