April 17, 2020(edited June 7, 2020)

Networked multiplayer games. This is a huge, not straightforward, thing to be done. That's true if we want to close some obvious doors for cheaters while also still keeping the game at a reasonable playable state because of inherent latency that can also be added on top of the physical lag caused by the network infrastructure.

I have published two tutorials (here and here) on this web site regarding how to setup networked multiplayer games with Godot. The overall necessary steps to achieve a synchronized multiplayer game through the network with snapshot interpolation is shown throughout both tutorials. Yet, just a little bit of network latency results in a somewhat unplayable experience because the shown method makes the client wait for the response from the server in order to update its state.

But there is also one rather problematic thing with that entire system. Adapting to a custom project may not be that difficult, however small changes in the game requires a bunch of updates in pretty much the entire networking system which obviously will lead to not so fun to hunt bugs. If one were to add client side prediction to hide the latency, it also brings another thing that must be verified whenever the game is updated.

This addon was born from the desire to automate most of the process to achieve a synchronized networked multiplayer game. Most of the design decisions behind it are meant to result in a less intrusive as possible system, that should not interfere (too much) with the game logic and, if possible, don't force any node hierarchy whatsoever.

When you see the code samples and/or the how to use tab, you will probably notice the fact that there isn't a node meant to be attached into your game object which will perform the synchronization. While this kind of node would be really nice, reality is that it would be really difficult to implement something generic enough to be useful. The problem is that often it's not enough to replicate only the "physical states" of the game objects (orientation, position and velocities). Anything that results in a visual display (player health for GUI, color of a banner and so on) will require replication, at least at some point in time.

The system consists in basically performing some initialization, creating a few short scripts meant to work as a bridge between the game logic and the snapshot system and perform some per game loop calls that are mostly telling which objects are part of the snapshots. In this most basic usage the result will be a client/server game that is in a similar state to the one that is achieved by following my other tutorials. In other words, absolutely no mechanism to hide latency.

Client side prediction is a technique used to try to hide network latency and consists in running the same game logic no only on the server, but also on the client machine. One may think that game logic should not be run on the client, but that's not really the case, provided the client does not directly tell the server anything about the game state. With this technique the client tries to stay ahead of the last received snapshot data, which represents a past state of the server (remember there is latency). When a new snapshot is received, the client must then compare with a corresponding internal prediction state, which is also client's past. If there are differences, then the client must perform the corrections accordingly. Because each project has to deal with this mechanism based on its code, the entire prediction and correction system cannot be part of the addon. Still, this tutorial describes how to achieve this technique using this addon. Also check the network and the complete examples in the demo project.

Two things to remember about this addon:

  1. It requires activation in the project settings, plugins tab.
  2. There is an internal dependency, more specifically the script.

There are a few limitations with this addon: