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

What this book covers

Chapter 1, Setting up a Server, explains what a network is and how Godot Engine implements networking features through its ENet library implementation. You’ll learn how to make your first handshake to effectively connect a server and a client machine.

Chapter 2, Sending and Receiving Data, discusses the foundation of a network, which is for multiple computers to exchange data with each other. In this chapter, you will learn that we use a data structure called packets, and we serialize data to recreate game states on the network. For this, we use the UDP protocol. At the end, we will have a login screen, effectively retrieving data from the server.

chapter 3, Making a Lobby to Gather Players Together, explains how Godot Engine eases the process of serializing and exchanging data using the industry-standard UDP protocol by providing Remote Procedure Calls (RPCs), allowing us to essentially make calls to methods on remote objects. By the end of the chapter, we expand the login screen into a lobby, adding another client to the equation and connecting three computers together.

Chapter 4, Creating an Online Chat, explains that with the power of RPCs, we can now change objects’ states remotely with ease. In this chapter, we learn how we use RPCs to allow players to exchange messages in a chat. We discuss how we can use RPCs and channels to prevent network bottlenecks. With that, we prepare ourselves to implement actual game features. By the end of the chapter, we will have a fully functional chat.

Chapter 5, Making an Online Quiz Game, explains how we can synchronize players’ game states based on the general game state. We will set up a server that will react to player interactions and change the game state from waiting for a response to processing a match winner, announcing the winner, starting a new match, and reaching the end of available quiz questions, effectively ending the game. By the end of the chapter, we will have an online quiz game where multiple players compete to answer the most questions correctly.

Chapter 6, Building an Online Checkers Game, moves on to implementing a turn-based multiplayer online game, and nothing is better than the classic checkers for that. In this chapter, we will learn how to get the most out of our RPCs while still maintaining the heavy processing on players’ machines. We will also discuss MultiplayerSynchronizer, a node that allows us to easily synchronize nodes’ properties remotely. We will also learn what Multiplayer Authority is, which prevents players from messing around with other players’ objects. By the end of the chapter, we will have a fully functional online checkers game.

Chapter 7, Developing an Online Pong Game, begins the transition from turn-based to action. Action games rely heavily on players’ reaction times, and the game world should update its state quickly to allow players to have a smooth experience. Here, we will develop an online Pong game and use the MultiplayerSynchronizer node to sync the players’ paddles and the ball. We will also learn that some features should use different syncing processes. We will go even deeper into the Multiplayer Authority realm to prevent one player’s input from interfering with the other player’s paddle’s movement. By the end of the chapter, we have a playable multiplayer online Pong game.

Chapter 8, Designing an Online Co-Op Platformer, is where our baby steps stop and we start to implement interesting features for a custom game. We will prototype a physics puzzle platformer game where players grab and move crates around to overcome obstacles and reach the level’s goal. Applying everything we’ve learned in the previous chapters, we will expand the usage of the MultiplayerSynchronizer by syncing animations on top of objects’ positions. By the end of the chapter, we will have a working prototype of a physics puzzle co-op platformer game.

Chapter 9, Creating an Online Adventure Prototype, is, if we’re honest, what you have been looking for throughout this book. Here, we will use all our skills to create an online multiplayer adventure game. Players can join and leave at any time and the world is persistent, maintaining players’ progress in quests. We will discuss the basics of making an MMORPG game, storing and retrieving players’ quest progress in a database, syncing players’ spaceships and bullets, and making their actions affect other players’ experiences. By the end of the chapter, we will have a prototype of an online multiplayer top-down space-shooter adventure game.

Chapter 10, Debugging and Profiling the Network, moves on from implementing the online multiplayer features on our top-down space-shooting adventure prototype. We now need to pave the way for thousands of players to play our game simultaneously. For that, we will use Godot Engine’s built-in debugging and profiling tools to assess the potential areas for improvements in our game. We will focus on the network profiler and the monitor debugging tools to assess and propose potential solutions for the bottlenecks we find in our prototype. By the end of the chapter, we will have two of the most powerful and necessary skills a developer can have: the ability to debug and optimize a game.

Chapter 11, Optimizing Data Requests, builds on the understanding of the tools we have at our disposal to assess the information we need to discover potential areas for improvement; now, it’s time to get our hands dirty. Throughout this chapter, we will learn how to create custom monitors to gather data about specific game features and decide the best strategy to optimize them. By the end of the chapter, we will have refactored our top-down space-shooting adventure, decreasing the bandwidth and the number of RPCs we make, effectively making our network consumption much lighter. We will have also implemented several techniques to decrease the network load, assessing each improvement with the network profiler and custom monitors to see how much better the game is becoming.

Chapter 12, Implementing Lag Compensation, deals with the issue that due to the improvements made to decrease network usage, our game may be inaccurately replicated on players’ machines. With fewer RPCs and more sparse synchronization, the game may become asynchronous among players. Add latency and packet loss on top of that and you effectively worsen the players’ experience. Nobody likes lag in their game. In this chapter, we will learn how to use Tweens to implement interpolation, prediction, and extrapolation to compensate for all these issues. By the end of the chapter, we will have a version of the top-down space-shooting adventure prototype with some fake latency and solutions for this game-breaking issue.

Chapter 13, Caching Data to Decrease Bandwidth, handles an important issue: throughout our network engineering endeavors, we have learned that bandwidth is our core resource and that we should always look to optimize its usage. In this chapter, we will learn how to use HTTP to download some data and store it on players’ machines so that we can reuse it when necessary. By the end of the chapter, we will have implemented a feature that allows players to use custom images for their spaceships, and this new image will be replicated on all other players’ instances of the game. To save bandwidth, we will implement caching using the user data folder.