Search Unity

RTS Style Game With Client-Side Prediction

Discussion in 'Multiplayer' started by Michael_Waltham, Sep 26, 2018.

  1. Michael_Waltham

    Michael_Waltham

    Joined:
    Aug 20, 2014
    Posts:
    31
    So, I am currently working on an RTS-like multiplayer game. Units are not controllable by players (they attack-move to a location automatically).

    I decided not to go full lockstep but instead do a state-based / prediction hybrid. The game is fully simulated on the client with a state packet for every unit distributed only once per second (Position, health etc.). I've read that this is quite a common method of doing things these days but i'm having major issues with it. One clear problem is with health syncing. Damage is dealt locally on every client machine and corrected via the state packet. This results in issues similar to this:

    * Projectile hits a unit on a client machine, taking him from 100 health down to 50.
    * Client only then receives a state packet from the server saying he is on 100 health which spikes it back up.

    Of course he will receive another corrective packet later on taking him back down to 50 but this causes really bad visual spikes. This issue gets even worse if you consider the impact of ability damage and such.

    Have I completely misunderstood what is required to create a client-predicted game or do I just need to treat every variable on a case-by-case basis? (I.E. Put in silly hacks to make the health not look bad).
     
  2. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Just off the top of my head - have a frame index, which runs locally and is also sent with the UpdatePackets. If you have a value which has changed locally @ frame 10, but you are receiving frame 8 data, don't update it - you need to wait to do a local update to the point where the incoming packets are the same time frame (ha ha) as the local update.