Book Image

The Essential Guide to Creating Multiplayer Games with Godot 4.0

By : Henrique Campos
3 (2)
Book Image

The Essential Guide to Creating Multiplayer Games with Godot 4.0

3 (2)
By: Henrique Campos

Overview of this book

The Essential Guide to Creating Multiplayer Games with Godot 4.0 guides you in exploring the built-in network API for online multiplayer games, offering practical knowledge through concrete use cases. Throughout the book, you'll assume the role of a network engineer in a fictional indie game studio, tackling real-world requests from your peers and gaining expertise in adding new network features to the studio's games. Following step-by-step instructions, you’ll go from making your first network handshake to optimizing online gameplay. You’ll learn how to sync players and pass data over the internet as you add online multiplayer features to a top-down shooter adventure game. This book puts you in a fictional game project team where you set up your first online server before advancing to creating an online chat system and transitioning local gameplay to go online. With a focus on implementing multiplayer features, you’ll create shared world adventures and learn optimization techniques to allow more players to join your virtual world. By the end of this book, you’ll have learned how to set up a client-server network, implement remote procedure calls (RPCs), sync node properties remotely, and optimize your games to create smooth online multiplayer experiences.
Table of Contents (19 chapters)
1
Part 1:Handshaking and Networking
6
Part 2:Creating Online Multiplayer Mechanics
12
Part 3:Optimizing the Online Experience

Introduction to a network

Making a network of connected computers is quite a task. In this chapter, we’ll understand the core concepts of online networks. We’ll also cover how Godot Engine provides solutions to each of the problems we may face in our quest to make online multiplayer games.

A network is a collection of interconnected devices that communicate with each other. In this communication, these devices exchange information and share resources with each other. You can have a local network, such as in a house or office, or a global network, such as the internet. The idea is the same.

For these devices to communicate they need to perform what we call a handshake. A handshake is how one device recognizes another device and establishes their communication protocols. This way, they know what they can request, what they expect to get, and what they need to send to one another.

A handshake begins with one device sending a message to another device. We call this message a handshake request. The devices use this message to start the handshake process. The one that sent the request waits for a message from the one that received it. We call this second message a handshake response.

Figure 1.1 – The handshake procedure

Figure 1.1 – The handshake procedure

When the requested device sends the confirmation through the handshake response, they establish their communication. After that, the devices start exchanging data. This wraps up the handshake process. We usually call the device that requests data the client. As for the one that provides data, we call it the server.

Note that we use these names for the very first interaction. After this first interaction, it is common that these roles change. In that sense, communication is dynamic. The server may request data from the client, and the client may provide data to the server.

In this chapter, we are going to make our first handshake using the Godot Engine Network API. We’ll also create and synchronize players’ data across the network. So, hold tight, as you’ll learn the following:

  • What the ENet library is and why we use it for games
  • How we can make a handshake using the ENetMultiplayerPeer class

For that, you’ll create a Godot project that lists connected players and allows them to edit and sync a line of text. It’s a simple but elegant project that covers the basics of setting up an online multiplayer environment in Godot Engine.