Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Authoritative server rigidbody set up

Discussion in 'Multiplayer' started by Sync1B, May 15, 2008.

  1. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    I am trying to make a arena style asteroids game and want a authoritative server set up. So I need some advice on the proper set up for this situation. I have not done any networking before this project, but I have read enough about the theory of networking that I understand what I want to do, I just need some specifics. I have gone through quite a few revisions to get at this point.

    The first thing I tried was a more p2p set up. The player sent its position to the server and the server distributed that. That was relatively easy and a good place to start with networking and I recommend others also start with some p2p. The trouble in a fast paced physics game is that the players easily got out of sync and often a collision would result in one object passing through the other object.

    I then decided that a more authoritative set up was better. What I ended up doing was using a RPC to send input every time it changed. Also I just simulated the movement of my player as if the player was the owner and tried to correct if things got too out of sync. I thought that the time between when input changes client side would be the same as the received changes server side. I was quite wrong, and things got out of sync very fast.

    So I have decided that best course of action would be to use OnNetworkSerialize to send input from the client and send transform info from the server. What I think I want to do is have two network views, one owned by the client and sending input and owned by the server sending the servers simulated movement. The one on the client side that is receiving position information will look at what the server simulated for position then go back and time and see if the client was right, if so continue, if not correct.

    So I am having real trouble on allocating network views, and what RPC sends what to where. Can I pass a allocated ViewID through the a RPC? What order should things happen? Should the server initialize the player, send it a allocated ViewID, do I then make another RPC that the client will send back, with its allocated ViewID? How can I wait to spawn the player until all this has happened. Some sudo code with the order of things would be awesome.

    Thanks so much,
    Bill
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Hi Bill,
    I'm working on something similar and my solution looks like this:

    Code (csharp):
    1.     //P2P Server uses this to initialize
    2.     void OnServerInitialized()
    3.     {
    4.         //Setup the play area
    5.         Code for creating a local copy of the static game space
    6.         //Allocate a new NetworkViewID
    7.         NetworkViewID mNVID = Network.AllocateViewID())
    8.         //Call an RPC to create my player
    9.         networkView.RPC("CreateMyPlayer", RPCMode.AllBuffered, mNVID, Network.player, 0);
    10.     }
    11.  
    12.     //P2P Clients use this to initialize
    13.     void OnConnectedToServer()
    14.     {
    15.         //Setup the play area
    16.         Code for creating a local copy of the static game space
    17.         //Allocate a new NetworkViewID
    18.         NetworkViewID mNVID = Network.AllocateViewID())
    19.         //Call an RPC to create my player
    20.         networkView.RPC("CreateMyPlayer", RPCMode.AllBuffered, mNVID, Network.player, 0);
    21.     }

    Code (csharp):
    1.     //Manually instantiate the player and assign the NetworkViewID
    2.     [RPC]
    3.     void CreateMyPlayer(NetworkViewID mNVID, NetworkPlayer mNetPlayer, int mAvatarBase)
    4.     {
    5.         //Setup the player GameObject
    6.         //Get the NetworkView of the GO and assign it's mNVID
    7.         //If I called this RPC, then let me control this avatars movement
    8.         if (mNetPlayer == Network.player)
    9.         {
    10.             //Code for wiring up the user input to the correct play GO
    11.         }
    12.     }
    So the idea is that the server first sets up its play area and player. The when any other clients connect, they do the same. We manually allocate a NetworkViewID to give each player control over their character, then download
    the texture and figure out where to place them.

    For networked physics, I can recommend some information kindly given by Larus.

    www.gaffer.org/game-physics/networked-physics
    www.gaffer.org/archives/gdc-slides-released

    Best regards
    Shaun
     
  3. smarcus

    smarcus

    Joined:
    Sep 18, 2007
    Posts:
    113
    Hey Shaun- I'm working on a similar project (with fast moving spaceships) and I'm currently poking at my non-authoritative setup and pondering a switch to authoritative and pushing everything through RPC... I guess I'd essentially be adopting a model/view/controller model, where clients were just views.

    Anyway, it seems reasonable enough to assume that this will resolve issues with collsions over a network- how does it affect speed in general, tho? Will all those RPCs slow down information transfer and negate the benefit of "unified" collisions?

    thanks!