Search Unity

Vr Networking game

Discussion in 'Multiplayer' started by CarolinePalardy, Jun 26, 2019.

  1. CarolinePalardy

    CarolinePalardy

    Joined:
    Mar 20, 2019
    Posts:
    7
    Hello,

    We're trying to create a VR Multiplayer game with two Oculus Rift. However, the client on the Network cannot grab objects and we encountered difficulties with syncing animations. Is there any system to work on VR Network specifically?

    so here is how the grab code goes for now. This bit goes on each hand because you cannot make a trigger a command and we can't put a Network Identity on both hands as they are child of the main body.

    Code (CSharp):
    1. public void OnTriggerEnter(Collider other)
    2.     {
    3.     if(other.gameObject.GetComponent())
    4.         {
    5.             CollidingObject = other.gameObject;
    6.         }
    7.  
    8. public void OnTriggerExit(Collider other)
    9.    {
    10.        CollidingObject = null;
    11.    }
    12.     }
    And the main body has this code for each hand. The command is supposed to execute the function even if this is a client. However, the client still cannot take object while this works perfectly for the Local host. (the host can move objects and the client will see them move. The client simply cannot grab anything, ever.)

    Code (CSharp):
    1. void Update ()
    2.     {
    3.  
    4. if(!isLocalPlayer){
    5. return;
    6. }
    7.     if(OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) > 0.2 && CollidingObject)
    8.         {
    9.             CmdGrabObject();
    10.         }
    11.     if(OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) < 0.2 && objectInHand)
    12.         {
    13.            CmdReleaseObject();
    14.         }
    15.     }
    16.  
    17.  
    18. [Command]
    19. public void CmdGrabObject()
    20.     {
    21.         objectInHand = CollidingObject;
    22.         objectInHand.transform.SetParent (hand.transform);
    23.         objectInHand.GetComponent().isKinematic = true;
    24.     }
    25.  
    26.  
    27. [Command]
    28. public void CmdReleaseObject()
    29.     {
    30.         objectInHand.GetComponent().isKinematic = false;
    31.         objectInHand.transform.SetParent (null);
    32.         objectInHand = null;
    33.     }

    If you've ever done that kind of Networking I could really use some help. I can also use something other than the Unity Network if there is something that specializes more in VR but for now I've never seen that kind of things in Photon either...

    Thank you for your time!
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    So your CmdGrabObject runs on the host, so on the host you set the parent. But I don't see where you are also setting the parent on the client. Also, are you sure that CollidingObject is being set on the host when the client calls CmdGrabObject?

    Lastly, is CollidingObject an object with a NetworkIdentity? If so, you shouldn't be assigning it a parent as NetworkIdentities aren't supported on child objects. If not, how are you syncing the position of CollidingObject with the clients?
     
  3. CarolinePalardy

    CarolinePalardy

    Joined:
    Mar 20, 2019
    Posts:
    7
    Doesn't the [Command] make it so that both the client and host can send it to the server?

    Funilly enough, the whole thing worked perfectly without the "(! isLocalPlayer)" except that only the host controlled when the CmdGrab and CmdRelease happened for both players. So I guessed it was the problem and added the line, now the client can't grab at all...


    Colliding object is an object with a network identity. So I should make it follow the hand with another method instead of setting a parent?

    Thanks for the insight I'll look it up :)
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    So a Command is sent to the server, but the code within the Command is not run on the client - and is only run on the server. Anything that modifies an object on the server doesn't sync to the client unless you have some mechanism for that syncing (transform position can sync with a NetworkTransform component, variables can sync through SyncVar, you can do other syncing by calling a ClientRpc within the Command, etc).
     
  5. CarolinePalardy

    CarolinePalardy

    Joined:
    Mar 20, 2019
    Posts:
    7
    I see, the hands are children of the GameObject "Body" and they are synced with a network transform child. So I guess ClientRpc is what I'm looking for so my method can be executed from a client... I'll check it out! thank you!