Hey !
So I am still working along with a few friends of mine on that multiplayer game project. For now we managed to advance quite a bit - we got a lot of the major systems going, including connexion and matchmaking. However, this being the first time I do networking in 5 years of tinkering, I ran into many problems with… latency.
What I’m currently working on are the movements of players, and more generaly entities, which includes many other things than players, mainly the little AI soldiers players will be able to summon. But I digress.
And of course I encountered problems with my system. It “works” but it’s very unsmooth, even with some extrapolation and interpolation going. So here’s how I’m basically doing it :
Every entity on the server and the client has a “movement” vector associated with it. As its name suggests it is applied to the entity’s position on the server every frame. When that vector changes, it is sent to the client along with entity’s ID so the client knows which one to apply the new movement vector to. The client also applies the movement vector to entities locally, except for a few ones, namely the one controlled by the player (because extrapolation needs to be done, so for example instead of waiting for the server to confirm the player’s entity movement vector changed after the player pressed a key, it starts moving the gameobject at the same time as it sends the “please change my movement vector” message to the server).
As for rotation, every player entity sends its current rotation to the server every 0.25 seconds, which in turn sends it to all the other clients.
On top of all this, every 2 seconds the server sends a “big” message with the current positions of all entities, as to prevent too much desync because of latency.
Now, I’m not sure it’s the best way to go about it. My thinking at first was that it was a good system because the server sends a small message and only when an entity changes its movement vector, as in when it is actually needed. But it’s very unsmooth : the server has problems tracking a player’s movement if he turns a lot, which is to be expected with a 0.25s rotation update period, not counting the time it takes for the message to reach the server. Of course I tried to lower that period but with so many messages sent every second the server was dying…
I still have time to completely refactor that system if needed, so I’m looking for someone with more experience to explain a better way to do this. It’s going to be a game with reflexes and such, so it has to be smooth and quick, while at the same time needs to be able to handle a few players (2 for now) and many MANY more secondary AI entities.
I thank you in advance for your help !