VR Player not appearing in character controller

I am developing a multi-player game in which a normal character controller user and a VR user can participate. Thus, there are two game modes through which the user can join, Normal and VR Mode.

I can control these modes, and the user can participate in any mode , but the problem in the Normal Player (charcter controller) cannot view the VR controller (HTC vive controllers), since these objects cease to be on the side of the character controller. So, how can I show the VR controller on the normal side of the player, which is what the VR player does.

(What I tried) I create an object and try to simulate its position and rotation relative to the VR controller, but it does not work, since the Simulation source (VR controllers) are turned off (on the side of a regular player, but they work in VR mode), and their position is not is changing. How can I show the vr controller to another user

+7
c # unity3d virtual-reality htc-vive
source share
1 answer

I managed to solve this problem using these steps after three attempts. This step is given below so that the future user is not stuck in this problem, since there is no other comprehensive guide:

  • Make one Gameobject for Head (simple cube) with Network ID and Network Transformation

  • Make one Gameobject for the (right) controller (simple cube) with network identification and network conversion

  • Make one Gameobject for (left) another controller (simple cube) with network identification and network transformation

  • Build all the above game objects.

  • Add all three collections to Network Manager (registered list of unprepared ancestors)

  • remove three compilations from the scene

  • Added below script (see comments for details) in my vr player and assign the appropriate prefabs and game objects

    public class VRPlayerCtrl : NetworkTransform { //source gameobjects head, left and right controller object of htc vive prefab public GameObject rightContSource; public GameObject leftContSource; public GameObject headObjSource; //prefabs to assign head, left controller, and right controller public GameObject vrHeadObjPrefab; public GameObject vrLeftCtrlPrefab; public GameObject vrRightCtrlPrefab; GameObject vrHeadObj; GameObject vrLeftCtrl; GameObject vrRightCtrl; void Start() { Debug.Log("Start of the vr player"); if (isLocalPlayer) { //instantiate prefabs CmdInstantiteHeadAndController(); //disabled conroller meshes at VR player side so it cannont be view by him vrLeftCtrl.GetComponent<MeshRenderer>().enabled = false; vrRightCtrl.GetComponent<MeshRenderer>().enabled = false; } } //Instantiate on start head and vr controller object so that it can be view by normal players void CmdInstantiteHeadAndController() { Debug.Log("instantiateing the controller and head object"); 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; } //sync pos on network CmdControllerPositionSync(); } //sync position on VR controller objects so that VR player movemnts/action can be viewd by normal user [Command] public void CmdControllerPositionSync() { vrHeadObj.transform.localRotation = headObjSource.transform.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; } } 

Congratulations on what you did!

+5
source share

All Articles