I am developing a Multiplayer game where a Normal Character Controller User and VR User can participate. So there are two modes of the games through a user can join,
I am able to manage these modes and user can participate with any mode but the problem is Normal Player (character controller) is unable to view VR controller (HTC Vive Controllers) as these objects become turn off on the side of character controller. So how do I show VR controller to the Normal player side that what VR player is doing currently.
(What I have tried) I make an object and tried to imitate its position and rotation with respect to VR controller but it is not working as Imitating source (VR controllers) objects are off (at the normal player side but working in VR mode) and their positions is not changing. How can I show the VR controller to other users in unity3d??
To turn the controller on, press the System button until you hear a beeping sound. To turn the controller off, press and hold the System button until you hear a beeping sound.
I have managed to solve this problem using these steps after trying hard three four days. These step are given below so that future user don't get stuck in this problem as there are no other comprehensive guide available:
Make one Gameobject for Head (simple cube) with Network Identity and network transform
Make one Gameobject for(right) Controller (simple cube) with Network Identity and network transform
Make one Gameobject for(left) other Controller (simple cube) with network Identity and network transform
Make prefab of all above gameobjects.
Add all three prefabs into Network Manager (registered Spawnable prefabs list)
delete three prefab from scene
Added below script(See comments for details) into my vr player and assign respective prefabs and gameobjects
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;
}
}
congrats you have done!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With