0
\$\begingroup\$

I am developing an online multiplayer 2D videogame with Unity as a client and a server programmed in c ++.

I do the synchronization of movement through an interpolation so that the movement is smoothed, but I have a doubt that I cannot find an answer anywhere.

In any multiplayer game when the client has a bad connection (lag) the character moves awkwardly and not fluidly, but in reality I don't understand why this behavior happens, currently in my game even though the client has a bad connection, it moves from fluid form because movement management is done locally and what is sent to the server is the player's position.

How can I produce this in my game?

Thank you very much and sorry for my level of English. Thank you

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Server lag happens due to the fact that the server has to verify data that is critical for gameplay. Usually in Online Games this data has mostly to do with:

  • positioning of actors
  • combat (who attacked whom, how much damage did they deal/take, ...)
  • player interactions (e.g. trading)

That means all the data that has the potential to influence the gamestate of other clients, needs to be verified by and synchronized by the gameserver(s). So after doing all the changes locally, they are sent (hashed and/or otherwise compressed) to the server, where the server does their own thing and tells the client either:

a) yep that's cool
b) nope that's wrong: here's what you should actually see

In addition to this, the client constantly will receive data from the server about the state of all other entities not controlled by the client itself.


Loads of data gets sent back-and-forth every second or likely even less. That data takes time to get to the server and back (roundtrip). If that time is longer than a tick (or maybe a few, really depends on your architecture..), the client has to make predictions. If these predictions are wrong, the local data needs to be adjusted to the real values received from the server.

\$\endgroup\$
3
  • \$\begingroup\$ Thank you very much for your quick response! I think I already understand how this works. For example, after receiving the input of controls to move the character, the position changes are made locally and a message is sent to the server with the new data (up to here it is how I have it currently programmed), but the server, as I understand it, must return to the customer (source of information) a verification message. Therefore, until the client receives this confirmation, will he remain frozen without being able to act? Is that why jerks occur when the connection is bad? Thank \$\endgroup\$
    – coantia
    Commented Sep 11, 2020 at 16:05
  • \$\begingroup\$ @Angel not entirely.. There is really not one single way to do this. It is a trade-off you see? Your client can simply assume it is correct until told otherwise (and then request a statedump from the server), or your client can always wait for the server to confirm that it is correct. You can imagine that if you have dozens of clients and all do their own thing, the game will look weird - actors being constantly reset and replaced (warping around). So usually a mix is used.. \$\endgroup\$
    – dot_Sp0T
    Commented Sep 11, 2020 at 16:12
  • \$\begingroup\$ Okay! I think I already understand how to work, thank you very much for your help \$\endgroup\$
    – coantia
    Commented Sep 11, 2020 at 16:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .