Search Unity

VR Multiplayer Controller Tracking Help

Discussion in 'Multiplayer' started by Mistafyed, Apr 20, 2017.

  1. Mistafyed

    Mistafyed

    Joined:
    Apr 18, 2016
    Posts:
    5
    If you have any kind of insight please help.

    I need to get multiplayer working in Unity using HTC Vive and UNET. The networking is just Host and Client via direct IP.

    I have gotten two people connected to each other and have made them able to see each other move by making the Player Prefab a cube with a headset model in it that adds a camera OnLocalStart() in the NetworkBehaviour script I wrote.

    The issue comes from functionality with the controllers. I have been trying all sorts of options and cannot seem to nail down the proper one.
    I cannot find anywhere that helps me be able to add the controller tracking or functionality onto my custom made cube controller. That would be one option.

    The main option I have been trying is pretty much editing the SteamVR [Camera Rig] to have prefabs take position and rotation of the locally tracked items like this:

    Made prefab GameObjects for Head, one for Right, and one for Left all with Network Identity and Network Transforms.
    Added all three prefabs into Network Manager (registered Spawnable prefabs list).
    Added this code to [Camera Rig]:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Networking;

    public class VRPlayerCtrl : NetworkTransform {

    public GameObject rightContSource;

    public GameObject leftContSource;

    public GameObject headObjSource;

    public GameObject vrHeadObjPrefab;
    public GameObject vrLeftCtrlPrefab;
    public GameObject vrRightCtrlPrefab;

    GameObject vrHeadObj;
    GameObject vrLeftCtrl;
    GameObject vrRightCtrl;

    void Start()
    {

    if (isLocalPlayer)
    {
    //instantiate prefabs
    CmdInstantiteHeadAndController();
    }
    }

    [Command]
    void CmdInstantiteHeadAndController()
    {
    vrHeadObj = (GameObject)Instantiate(vrHeadObjPrefab);
    vrLeftCtrl = (GameObject)Instantiate(vrLeftCtrlPrefab);
    vrRightCtrl = (GameObject)Instantiate(vrRightCtrlPrefab);

    // spawn the bullet on the clients
    NetworkServer.Spawn(vrHeadObj);
    NetworkServer.Spawn(vrLeftCtrl);
    NetworkServer.Spawn(vrRightCtrl);
    }

    void Update()
    {
    if (!isLocalPlayer)
    {
    return;
    }

    CmdControllerPositionSync();
    }

    [Command]
    public void CmdControllerPositionSync()
    {
    vrHeadObj.transform.localRotation = headObjSource.transform.parent.localRotation;
    vrHeadObj.transform.position = headObjSource.transform.position;
    vrLeftCtrl.transform.localRotation = leftContSource.transform.localRotation;
    vrRightCtrl.transform.localRotation = rightContSource.transform.localRotation;
    vrLeftCtrl.transform.localPosition = leftContSource.transform.position;
    vrRightCtrl.transform.localPosition = rightContSource.transform.position;
    }​

    What I am finding out is that it seems when using Player Spawning I can spawn both players just fine, but when spawning the Camera Rig as the player then instantiating these objects, the host cannot see the client but the client can see the host. This makes me think that the instantiating is not coming back to the host properly.

    Please help if you can. I appreciate anything you can give me.


    Here is what some of my assets look like: http://imgur.com/NmwA57R