Jump to content
  • Advertisement
Sign in to follow this  

Unity Deterministic Battles (LockStep)

This topic is 1409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone,

I hope this is the right subforum, I am new here.

I am currently programming a RTS with the focus on multiplayer, using both Unity and my own C++ Engine (just core, no graphics, I still don't trust Unity to be deterministic).

After solving basic problems and now being able to do standard stuff which has no interaction between the players (constructing, walking), I am up to implement the "fights".


My Units walk grid-based to get rid of nasty floats (the animation still has them though, so you don't see the "hopps"), so this seems to be deterministic. But now I need to ensure that fights have always the same way to happen. Currently my Unit have a Combat-Script, but I don't know in which order Unity checks them, so I wanted to write myself a combatmanager, doing all the fights all over the map.


Now I am not sure how to handle problems like the "first hit". When two enemy units encounter, how do can I be sure that always one unit gets off the first hit? Or am I missing something very basically here, because I didn't found anything regarding that on the web.

Edited by thetemplar

Share this post

Link to post
Share on other sites

for deterministic multiplayer you don't need to do what you're doing with ints vs floats.


all you really need to do is use the same seed for all random number gens, and standard game architecture takes care of the rest.


update_all takes the form of:

for each entity: update_entity.


as long as you iterate through the entities in the same order each time   -   using something like for i=0; i<num_entities; i++;   -    entity n will always attack before entity n+1, and so on.


make sure your net lag prediction and fixup code is deterministic, and that's pretty much it.

Share this post

Link to post
Share on other sites



Check that out about deterministic floats.


In a lockstep approach, those issues shouldn't be a problem. You need to calculate the simulation in advance, and only display what happened in the past. That way you can be 100% sure all clients match (lockstep).


Frame 1

players give input


Frame 2

Server confirms input


Frame 3

Server executes input, and returns to all players


Frame 4

Server waits for additional input.


So at the end of that, the clients are just see'ing the first frame, really. If there's any kind of desync, you've got a problem in your basic structure. Don't execute any simulation without server input, basically.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!