Search Unity

Lock-Step Multiplayer Rts Question

Discussion in 'Multiplayer' started by Zhosay, Jul 3, 2012.

  1. Zhosay

    Zhosay

    Joined:
    Dec 12, 2011
    Posts:
    98
    Hey,

    I'm currently developing a Lock Step Multiplayer Rts engine (for learning purpose). Now I read alot of blog posts about it like the Age of empire one. http://www.gamasutra.com/view/feature/3094/1500_archers_on_a_288_network_.php/

    But I miss or don't get the one point. So If I say one step is 200ms.

    Step 1 Example:
    Player a gives the command to move his unit to x/y where x/y is a distance of 100.
    Player b gives no command empty one.

    Is the unit running the 100 distance "live"? Or is it cut down in 200ms Segments / Steps? Or how is the movement then done?

    Greetings
     
  2. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    My take on it is that the model runs at a fixed rate (e.g. 5Hz = 200ms ticks). For the player's sake, the "view" code smooths the motion, applies animation overlays, and so on.
     
  3. Zhosay

    Zhosay

    Joined:
    Dec 12, 2011
    Posts:
    98
    Thanks for the awnser.

    That I get you right when you would have pause between 2 ticks there would be a stop for the model? Guess thats why you send the current command to the next tick rather then the actually.
     
  4. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    Sort of - in client-server, clients can't tick their model until they receive the right tick packet from the server, and in peer-to-peer they can't tick until they've received the corresponding tick packets from all the peers. To avoid stalls, you need the packet senders to be somewhat ahead of the packet receivers, so that by the time the packets arrive they're not late.
     
  5. Zhosay

    Zhosay

    Joined:
    Dec 12, 2011
    Posts:
    98
    Okay yea thats the same written in the guide.

    Movement is easy that way. Commands while in tick 1000 will be executed in tick 1002.

    But that way I have a problem with attacks etc. how do you time an attack that goes like 1 second or a half second.

    Example: Long archer shot (reload, pull, shot), Or casting a spell over a half second castime

    As there is then a tick between reload and pull. Or while casting. I don't like the idea to say you cast 2 ticks you attack 1 tick. As cast speed for heros would then be useless if you need to get a full tick.

    Hope you get my point. And thanks for the help again.
     
  6. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    This networking model isn't really suitable for reaction or timing-based gameplay - it's designed for RTS-style games where your input is rather high-level, and the characters' AI does most of the detailed work. But that doesn't rule out the kind of thing you're talking about, you might need some compromises though.

    Levelling up is still useful as the character can attack more effectively when on autopilot - e.g. you issue an attack order, the character attacks, and benefits from a faster reload, for example. This kind of behaviour within the model, independent of the control scheme, is ideal.

    If you do want skill in your control scheme, you can still put that logic in the view code, and use the accurate timings taken from the view to add a "power" field to the shoot command. The problem with this is that you become vulnerable to client hacks, against which - in the client-server scheme - this method is otherwise fairly strongly protected. If you don't care about that then this is still a viable option - you can still send a "begin casting" command, so other players can see the visual effect, but do your accurate skilled timing checks in the local view and add the result to an "end casting" command, at which point the model applies the effect of the spell. The exact time spent casting as far as the model is concerned (rounded to the nearest tick) is not critical.

    One other point - your model doesn't have to have a low tick rate. If you make a distinction between model ticks and server ticks (call those something else, e.g. turns), then you can have the model tick at 100Hz but only send turns at 5Hz. This increases the model's time resolution, allowing more interesting AI decisions, at the expense of using more CPU, but doesn't affect the network bandwidth at all.
     
  7. Zhosay

    Zhosay

    Joined:
    Dec 12, 2011
    Posts:
    98
    Okay guess thats the reason why I had a hard time finding out how to solve this.

    For my Game I require Heros like in the moba game but alot more units then in moba games like 100-200 Units on the field. Guess I really have to find a half half thing there. As you said rather high timing. May give the client more rights.

    Gonna try some stuff the next days.