• Register

Tiny Tanks is an 8 player multiplayer game with toy tanks that blow each other up in a completely destructible arena. With hundreds of game modes and modifier combinations, each round is different.

Post news Report RSS Tiny Tanks Online Multiplayer – How we enable hundreds of debris over network

At a certain point during the development of Tiny Tanks, we decided that the game would need Online Multiplayer. So we set out to add a high quality multiplayer to the game, not knowing how many hurdles we would have to overcome. In this article, I want to go over how I tamed one of the beasts of the game: The fully destructible environment.

Posted by on

We want to play online, what do we have to do?

Tiny Tanks features a massive amount of destruction. You can blow up the whole map into small pieces and drive around on them. They influence the gameplay and therefore, we have to somehow synchronize them when you want to play online. But why is that important?

syncdebris


Why online multiplayer + physics is a horrible idea

We can we not just run the physics simulation on everyone’s PC and just watch the game run fine? That is because of a thing called determinism, or to be more precise: non-determinism. What does that mean? When we run a deterministic physics simulation a few times, we expect the same things to happen exactly each time. No matter if we run it on a different PC or not. The problem is NVIDIA PhysX is only deterministic under very, very special conditions. Now the problem we face is the following: If we just let the simulation run on everyone’s PC without checking if all the simulations are running exactly the same, we will have great chaos very quickly. For one player half of the map could be gone and another player could still have most of the arena intact. And therefore, we have to make sure that everything is running the same for everyone and if not, we have to correct it to be the same again. Below you can see what it looks like when we force all the players to do the same thing, even if the physics may say something different.

forcingCorrections 1


But how much bandwidth do I need?

So, how do we do that? The solution is to send so-called snapshots or states from one of the players – the host – to all the other players. However, if we just send the raw states to the other players, we quickly run into trouble. Let’s imagine how much data the host would have to send to the other players. Our standard level consists of 65 blocks, which in turn each consist of 10 debris pieces. The worst-case scenario would be to send updates for each debris 60 times per second, consisting of the position and rotation, taking 16 bytes, totalling roughly 10 Mbits/s having to be sent. Now it doesn’t stop there. This data has to be sent to all the players. For 8 players that would mean the host would have to send 70 Mbits/s, which of course, is not really desirable.

yourrouter


Let's tackle this behemoth one step at a time

There are a few ways to counter this. The first step is to lower the rate at which the data is sent. We can go down to 20 times per second, that way we can – with the snip of a finger – cut the data by over 60%. Now we just have to add some smoothing, called interpolation to the movement so the debris looks nice and smooth when moving around.

Next, we can use delta compression. That means, we only send data when the values are different. When debris is not moving, we don’t send data. As most of the time the debris are actually not moving, we can save a huge amount of data.

Another technique we can use is to compress the position and rotation. We know that the debris will not move too far away from the centre and we do not have to know the position down to the micrometre. A few centimetres of accuracy is plenty enough. Doing this, we can reduce the size of the individual data from 16 bytes to roughly 6 bytes. Again, we reduced the sent data by roughly over 60%.

Tanks driving around


Looks like this could actually work!

Of course, there are a few more tricks, but using just these techniques we can reduce the traffic maximum from 70 Megabits/s to just under 10 Mbits/s. This still sounds like a ton, but remember that this is the traffic we would use up if all debris was to move at the same time. Due to delta compression, we only move 5-20% of the debris at a time. Meaning we realistically need 2 Mbits/s MAX as the host. The rest of the players will need even less.

compare


Where do we go from here?

All of this took us a few weeks to get right and there are more things we had to incorporate. This is just to give you a glimpse at what we are actually doing to make the game run smoothly. We are still working hard towards a satisfying online experience, but we are very close to finishing it.

If you want to stay updated, make sure to follow us on our social media platforms.

Discord: Discord.gg
Website: Leadfollowgames.com
Twitter: Twitter.com
Facebook: Facebook.com
Reddit: Reddit.com

Hope you enjoyed the article and thank you for reading,

Lukas
LeadFollow Games

Post comment Comments
frankadimcosta
frankadimcosta

Very interesting !!! TNX a lot !

Reply Good karma Bad karma+1 vote
Guest
Guest

This comment is currently awaiting admin approval, join now to view.

Healstation
Healstation

Cool rundown of the troubles of client/server sync.

Reply Good karma Bad karma+1 vote
VaTTeRGeR
VaTTeRGeR

Check out this article and the followup article (snapshot compression) if you want to know exactly how to achieve this: Gafferongames.com

Reply Good karma Bad karma+2 votes
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: