Search Unity

LockStep Networking, how often should I network data?

Discussion in 'Multiplayer' started by Crayz, Dec 17, 2014.

  1. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    194
    I've been working on an RTS core lately and recently began to implement networking features. Spent some time researching and found that a LockStep networking model is the way to go. I'm going to begin implementing unit movement, damage, attack, etc., into the network but I'm curious just how much data should be passed through to the network? LockStep keeps all players in sync as far as I know.

    Currently my plan is something like this.. when a unit is commanded to walk towards an enemy and begin attacking I'll network once to all clients the attacking unit's ID and target's location. When this data is received, the unit will build a path to its target and begin moving on the client side. Assuming all data remains in sync between each client, on the client's side the attacker will eventually come within attacking range and begin attacking without requiring any extra data from the network.

    When the target being attacked is commanded to run away the attacker on the client side should know that it can't attack any longer and needs to start chasing again, resulting in networking movement data to each client, updating paths and beginning movement on the client's side.

    My question is, should I be networking every action that takes place between the units? i.e. when the unit begins attacking, when the unit finishes attacking, when the unit needs to chase down its target again, etc., or will it be sufficient to network just the movement and let the client handle the rest?

    Hopefully this wasn't too hard to understand, I'm a complete newbie to networking :confused:
     
  2. Louis-Getz

    Louis-Getz

    Joined:
    Nov 5, 2012
    Posts:
    6
    That method would work if every implementation on each machine calculated identical routes. You could accomplish this if you created your own path finding algorithm that rounded off to a certain point (eliminating the likely-hood of a slowly de-syncing client).

    You can't use Unity physics because even under identical initial conditions, the clients could calculate different results. These results get further and further off extremely quickly. This is caused by two major factors: butterfly effect, floating point differences (one machine will calculate x=2.0000001 the other may calculate x=1.9999999).

    Do not get discouraged however. It is very possible and has been done plenty of times.

    Now anyone can feel free to correct me but I believe if you met these conditions you could do it.
    (Keep in mind this is not some concrete formula, I am just thinking out loud here really.)

    1. On the client and the server, always round off numbers to a predefined distance (say the 5th or 6th digit).
    2. When a client asks to move the group of units, send that request to the server and the location of the click.
    3. The server sends the units involved, initial coordinates, and target location of the units.
    4. Using identical, rounded algorithms, the clients calculate the paths of each unit.

    Bonus. The server could calculate a rough path (say 4 or 5 points spread across the path evenly) and send that as well.

    Hopefully you can extract a method that works for you from my example.

    EDIT: I responded before I actually finished reading your question 0.0

    To answer the question you ACTUALLY asked:
    Only send to the server commands that a player enacts.
    Let the clients handle results of a player command

    Key:
    Items in brackets [ example ] are the networked commands
    Items in curly brackets { example } are the processes

    For example:
    Player 1 clicks to move 4 units (a,b,c,d) to position x. [Player 1 -> Server : Command move]

    [Server -> Player 1,2,3,...,n : Command move on units (a,b,c,d) to position x]

    {Clients read the command from server, calculate the paths, move the units.}

    Player 1 uses 3 units (a,b,c) to attack a unit (f) [Player 1 -> Server : Command attack]

    [Server -> Player 1,2,3,...n : Command attack on units (a,b,c) -> unit (f)]

    {Clients read command attack, begin (looping) attack animation, enable following algorithm if necessary}

    Player 2 clicks to move unit (f) away from attackers (position y) [Player 2 -> Server : Command move]

    [Server -> Player 1,2,3,...,n : Command move on units (f) to position y]

    {Since unit (a,b,c) are attacking, they follow and attempt to continue attacking on each client}
     
    Last edited: Dec 23, 2014