In this multi-part tutorial I’m going to detail the necessary steps to setup a multiplayer game in Godot. The documentation offers some good information regarding the networking system, however it may not be very clear how to actually use it. There are a few video tutorials out there, most notably Game From Scratch and Zerosploit Youtube Video. Both are in video format and some people may prefer written ones. This is where this tutorial comes in.
EDIT: Menip has published this set of tutorials which is a really good source of information.
There is also something to mention, the vast majority of tutorials work with a lobby to perform the initial synchronization of players, including spawning their characters. But what if you want to immediately enter the game when the “create server” button is clicked and then players can join at any time? This is the case explained here. Hopefully the concepts shown in this tutorial are enough for you to expand and adapt into your own projects!
A brief overview of what exactly we will do in this tutorial follows. When the “game” is launched we will be in the main menu, where we can choose between joining or creating a server. We also have some rudimentary character customization presented, namely the color of the icon representing the player (which will be the default Godot icon). Within the server’s creation options, we can define the maximum amount of players along with server name and it’s listening port. Once the server is created, we move into the game scene and spawn the character with the customization applied to it. Then, we complete the number of players with “bots”. In this case, those will perform just random movements (of course we could delve more in the AI but that’s not the point of this tutorial anyway). When a new player connects into the server, that player’s scene is also changed into the game world, getting it’s own character and a synchronization between the other players and bots. Ahh, yes, those “AI” controlled things will dynamically be created/removed based on the amount of real players in the server.
In short, this tutorial will cover:
Now, I will assume you know how to operate Godot editor. Namely, how to create scenes, nodes, scripts, attach scripts to nodes and export your project as a distributable. This last part is somewhat important since it’s the only current way for us to test multiplayer games. Don’t worry, it won’t be necessary to have multiple machines to perform the tests, just a machine that is capable of running multiple instances of the game.
Only Godot (v3.1) will be needed for this tutorial. We will re-use the default Godot icon to represent the players and “AI” avatars so no need to worry about game art or anything.
This tutorial is structured in the following way:
Throughout the tutorial if you feel confused or need some more reference, you can grab the entire resulting project from my GitHub Repository