VR Player Prefab Setup

Options
I'm currently building a VR multiplayer game using VRTK along with PUN but I'm a bit confused on how the VR player prefab should be set up. At the moment I have the player prefab intantiated into a multiplayer level when connected but this includes the camera rig. I've seen a video online demonstrating something similar, except they had the camera rig already in the level and they create a separate avatar with a head and hands that was instantiated into the level instead. I'm going to be doing the same myself, but is this a proper way to go about it? Everyone who joins a game will have a local version of the camera rig and they'll use that? Also how would this affect spawning in different locations, would I need to move the camera rig around or would the avatar itself be moved only?

Comments

  • Ok I was able to get part of the VR player to show up in a room, but nothing is being synced in terms of movement tracking. I'm using one VR player and one generic player (non-VR) to test since I only have one headset at the moment. I play the game on separate computers and I can see when the VR player spawns in with the hand models but they stay on the ground.

    I am instantiating the entire camera rig along with the models. The models are grouped outside of the camera rig prefab with Left Controller and Right Controller as empty game objects with an actual mesh of a hand as a child of it. It seems when I used the models as a child of the actual controllers in the camera rig they were not visible at all in the room.

    I have a Photon View and Transform View components on both the left controller and right controller (not on the camera rig). Am I supposed to sync something else? What could be the issue here.
  • Hi @jgonzosan,

    I guess you have to implement a custom OnPhotonSerializeView solution and attach this to the parent object. On this parent object, you also need to attach a PhotonView component, which observes the previously mentioned OnPhotonSerializeView function. This object can be network instantiated by using PhotonNetwork.Instantiate.

    The OnPhotonSerializeView function needs to synchronize the position and rotation of the child objects (left and right controller). You also would have to enable or disable the Camera Rig or the camera component, which is also part of the object. If the local client is the owner of the object, the camera should be enabled, and disabled otherwise. You would also have to think about how to synchronize movement of the entire object - if this is possible at all. I'm not sure about the usual VR Prefab setup, but as far as I would say you can either move the new parent object or the Camera Rig (in this case I would make the Camera Rig the parent of the object and attach PhotonView and the OnPhotonSerializeView component to it).
  • Thanks. I actually got it working but it took a bit of experimentation and help from someone else. For anyone else struggling with this I'll put what worked for me so far.

    First I created the VRTK manager/SDK Manager along with the camera rig as one separate group and placed that in the level(s). The player prefab that gets instantiated is a separate group as well that contains both the controllers and any meshes attached to those controllers. I also have a play area game object in that group as well.

    So when I join a room the VRTK manager group is already present. In order to sync the movement of the controllers with the camera rig present I created a small script that just assigns the controllers to the VRTK manager for the left and right controller. Both of these controllers also have a Photon View along with the Smooth Sync script. I applied this to every object in the player prefab group (controllers/body).

    At the moment I'm testing this solely with one VR player and a generic camera/cube as a second player just to see if I can see the VR player movement syncing across the network. I will need to implement some checks to see if I'm the local player and disable the camera rig.

    I assume disabling/enabling the camera rig is all I would need to do in order to prevent the local player from controlling the instances of the player in the game?





  • jgonzosan
    jgonzosan
    edited September 2018
    Options
    I finally tested this with another VR player and unfortunately was not able to play. The game essentially freezes the camera so it feels like the entire world is connected to the headset. I assume this has something to do with two VR players being created. For the game I have the camera rig and VRTK manager in the level, it's not instantiated. I only instantiate the player avatar which has the controllers and head that sync with the camera rig in the level.

    On the player avatar I have this script which allows me to assign the controllers and head for proper syncing to the VRTK manager. Below is the script:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using VRTK;
    
    public class PlayerController : Photon.PunBehaviour {
    
    	public GameObject leftController;
    	public GameObject rightController;
    	public GameObject VRTKManager;
    	public VRTK_TransformFollow followScript;
    
    
    
    	// Use this for initialization
    	void Start () {		
    
    		if(photonView.isMine){	
    		
    		followScript.gameObjectToFollow = ViveManager.Instance.head;
    		GameManager.Instance.localPlayer = this.transform;
    		VRTK_SDKManager.instance.scriptAliasLeftController = leftController;
    		VRTK_SDKManager.instance.scriptAliasRightController = rightController;
    		
    		}
    		else
    		{
    			GameManager.Instance.VRTKManager.SetActive(false);
    			GameManager.Instance.cameraRig.SetActive(false);
    		}
    		
    	}
    	
    
    }


    Is this the right way to approach this? If the photon view is mine then I assign controllers and local player. If it's not mine, then I disable the VRTK manager and camera rig.
  • Eisen
    Options
    r u trying with 2 computer ?
  • jgonzosan
    Options
    I was able to fix the issue. The freezing was due to me trying to add a script as an observable object but it didn't have the proper method included in the script. I removed it from being an observed object and it worked. I actually didn't need to disable anything in the game since each player had the camera rig locally in the map and it was not instantiated.