Search Unity

How to handle network correctly ?

Discussion in 'Multiplayer' started by acropole, Mar 2, 2010.

  1. acropole

    acropole

    Joined:
    Aug 13, 2009
    Posts:
    171
    Hi,

    At this time I've coded the network like this :

    The client send input to the server when things change, with an RPC.
    The server send this data to all clients.
    The clients lerp their position and rotation to the server position and rotation like this :

    Code (csharp):
    1.         if(Network.isClient){
    2.             transform.position = Vector3.Lerp(transform.position, serverPos, Time.deltaTime * 5.0);
    3.             transform.rotation = Quaternion.Lerp(transform.rotation, serverRot, Time.deltaTime * 5.0);
    4.         }
    5.  
    So even if their is no accuracy between client and server physics it's fixed immediatly.

    It works fine but their is lag. I test it with the server and client on the same computer.
    When I violently move the mouse, the player's camera move to the desired rotation but move back a bit (due to the lerp).

    The problem is that I must lerp things because of collision, but there is those laggy and unaccurate mouse movements.

    Any advice about networking all this correctly ?

    Thanks.
     
  2. cerebrate

    cerebrate

    Joined:
    Jan 8, 2010
    Posts:
    261
    I would probably let the camera be entirely client controlled, as it doesn't really affect gameplay (it's only showing something different to the client).
     
  3. acropole

    acropole

    Joined:
    Aug 13, 2009
    Posts:
    171
    The camera is bound to my player, it rotate the same. So it cannot be client side controlled because of physics.
    I tried it before and the client and server don't look at all in the same direction after some collisions.