The Essential Guide to Creating Multiplayer Games with Godot 4.0 - Henrique Campos - E-Book

The Essential Guide to Creating Multiplayer Games with Godot 4.0 E-Book

Henrique Campos

0,0
35,99 €

oder
-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Veröffentlichungsjahr: 2023

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



The Essential Guide to Creating Multiplayer Games with Godot 4.0

Harness the power of Godot Engine’s GDScript network API to connect players in multiplayer games

Henrique Campos

BIRMINGHAM—MUMBAI

The Essential Guide to Creating Multiplayer Games with Godot 4.0

Copyright © 2023 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Rohit Rajkumar

Publishing Product Manager: Vaideeshwari Muralikrishnan

Book Project Manager: Sonam Pandey

Content Development Editor: Debolina Acharyya

Technical Editor: Reenish Kulshrestha

Copy Editor: Safis Editing

Proofreader: Safis Editing

Indexer: Tejal Daruwale Soni

Production Designer: Prashant Ghare and Jyoti Kadam

DevRel Marketing Coordinators: Nivedita Pandey, Namita Velgekar, and Anamika Singh

First published: December 2023

Production reference: 2201223

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK

ISBN 978-1-80323-261-4

www.packtpub.com

To God, who has always been me with me, blessing me with strength, faith, and determination to take faithful steps throughout this journey. Let this book be a blessing that will allow people to make amazing creative endeavors.

– Henrique Campos

Foreword

Henrique, better known as Pigdev in the Godot sphere, was one of the first content creators covering the engine back in the day. He’s always been dedicated to open source software.

We worked together for a couple of years, and I’m glad to see how Henrique has grown into one of the few old-timers who are still constantly learning and sharing with the community.

Most resources for Godot focus on helping newcomers learn the basics. With this essential guide to creating multiplayer games with Godot, we finally have a learning resource dedicated to online multiplayers. At the time of release, it is one of the areas of Godot that lacks learning resources the most.

I especially appreciated the last three chapters, as they dive into essential techniques such as lag compensation and optimizing network requests. Serious real-time multiplayer games absolutely need them, yet information on these topics can be especially hard to find.

I hope you’ll have a great time with this essential guide to multiplayer in Godot, and I can’t wait to see more multiplayer Godot games thanks to it.

Nathan Lovato

GDQuest founder

Contributors

About the author

Henrique Camposis an indie game developer and game designer working in the industry since 2015. Starting as a university teacher in the Computer Graphics and Artificial Intelligence chairs and working for the GDQuest team from 2018 to 2022, he also provides consultancy for solo developers, studios, and schools.

Under the alias of Pigdev, Henrique has been creating game development content on his YouTube channel since 2016. Among his projects, he wrote the Top 7 Godot Engine Recipes and Platformer Essential Recipes e-books, where he presents design patterns that people can use to make games with the Godot Engine.

A passionate open source enthusiast, Henrique has been working and contributing to the Godot Engine project since 2016.

I want to thank God, my friends, and my family, especially my sister, Ráisa, my mother, Sheila, and my father, Claudio, for always being by my side and supporting me throughout my journey of empowering indie game developers.

I also want to thank the whole Godot Engine community for building and supporting such an amazing tool.

About the reviewer

Yogendra Manawat is an indie maker and computer science student. While he is primarily focused on development skills, he’s also experienced in programming languages including C++, Python, C#, TypeScript, and GDScript.

His passion for games and movies led him to explore 3D animation with Blender. Yogendra has over three years of game development experience, having created several small games. Currently, he’s focused on his original story-based game, Bleak, built using the Godot Engine.

Yogendra loves learning new technologies and experimenting with development techniques to create unique games and useful software. He’s an active contributor to the Godot Engine community and has developed tools, including Coursefy and Vortexorama, using Godot. Yogendra actively engages in game development forums, collaborating and exchanging ideas with fellow developers.

Table of Contents

Preface

Part 1: Handshaking and Networking

1

Setting up a Server

Technical requirements

Introduction to a network

Understanding the ENetMultiplayerPeer class

What is the ENet library?

What is the UDP protocol?

How does this connection happen?

Creating the server

Creating the client

Testing our handshake

Summary

2

Sending and Receiving Data

Technical requirements

Understanding packets

Introduction to the JSON format

Serialization

Sending packets with PacketPeerUDP

Creating an AuthenticationCredentials Autoload

Sending players’ credentials

Listening to packets with UDPServer

Authenticating the player

Loading a fake database

Replying to the authentication request

Maintaining the player’s session

Loading the player’s avatar

Summary

3

Making a Lobby to Gather Players Together

Technical requirements

Calling functions remotely with RPCs

Introducing the @rpc annotation

What’s necessary for an RPC?

Understanding the multiplayer authority

Comparing UDP and ENet approaches

Remaking the login screen with RPCs

Establishing an ENetMultiplayerPeer connection

Creating the RPC functions template

Authenticating the player

Adding the player’s avatar

Cleaning AvatarCards

Retrieving players’ avatars

Testing the lobby

Summary

4

Creating an Online Chat

Technical requirements

Understanding data exchange and channels

Reliable and unreliable packets

Understanding channels

Sending chat messages

Updating peer’s data remotely

Summary

Part 2: Creating Online Multiplayer Mechanics

5

Making an Online Quiz Game

Introducing the online quiz game

Setting up a lobby for the quiz game

Displaying new players

Starting the match

Implementing online turns

Updating players about the round

Turning local mechanics into remote gameplay

Understanding the questions database

Loading and updating questions

Sending players’ answers to the server

Summary

6

Building an Online Checkers Game

Technical requirements

Introducing the Checkers project

Understanding the Checkers Piece scene

Comprehending the FreeCell scene

Introducing the CheckerBoard scene

Serializing players’ turns

Working with MultiplayerSynchronizer

Updating and syncing the CheckerBoard

Handling remote turn shifts

Setting up players’ teams

Enabling and disabling team pieces

Managing win and lose conditions

Summary

7

Developing an Online Pong Game

Technical requirements

Introducing the Pong project

How the player paddles work

Understanding the Ball scene

Managing players’ scores

Tying everything together

Setting up online multiplayer paddles

Changing the paddle’s owner

Assigning the players’ paddles

Syncing remote objects

Updating the ball’s position

Coordinating the paddle’s position

Summary

8

Creating an Online Co-Op Platformer Prototype

Technical requirements

Introducing the platformer project

Understanding the Player class

Unveiling the Crate class

How the InteractiveArea2D class works

Understanding the PlayerSpawner class

Spawning players in the match

Giving players control in PlayerSpawner

Setting up the Player multiplayer controls

Syncing physical objects

Synchronizing the player’s position and animations

Updating the crate’s position remotely

Summary

9

Creating an Online Adventure Prototype

Technical requirements

Introducing the prototype

Understanding the Player scene

Gauging the Asteroid scene

Unraveling the quest system

Breaking down the World scene

Logging the player in to the server

Authenticating players

Syncing the World scenes

Separating server and client responsibilities

Shooting bullets on all instances

Calculating an asteroid’s damage

Storing and retrieving data on the server

Implementing the quest system’s client side

Implementing the quest system’s server side

Summary

Part 3: Optimizing the Online Experience

10

Debugging and Profiling the Network

Technical requirements

Introducing Godot’s Debugger

Mastering the Stack Trace tab

Debugging with the Errors tab

Exploring the Profiler tab

Exploring the Visual Profiler tab

Exploring the Monitors tab

Getting to know the Video RAM tab

Grasping the Misc tab

Understanding the Network Profiler

Identifying the project’s bottlenecks

Using the Network Profiler

Using the Monitors tab

Summary

11

Optimizing Data Requests

Technical requirements

Understanding network resources

Decreasing the requests count

Reducing the weapon fire count

Decreasing Asteroid’s syncing count

Compressing data with the ENetConnection class

Summary

12

Implementing Lag Compensation

Technical requirements

Introducing lag issues

Dealing with unreliable packets

Common compensation techniques

Implementing server-side motion

Bridging the gaps with interpolation

Playing ahead with prediction

Gazing into the future with extrapolation

Summary

13

Caching Data to Decrease Bandwidth

Technical requirements

Understanding caching

Setting up the HTTPRequest node

Understanding the HTTP protocol

Setting up the scenes and database

Implementing texture caching

Implementing database caching

Going further with caching

Summary

Index

Other Books You May Enjoy

Part 1:Handshaking and Networking

Throughout this part of the book, we take our first steps into the realm of networking. We start by making a handshake using Godot Engine’s high-level EnetMultiplayerPeer class. We also learn how to use the UDP protocol to exchange data and end up by learning how to use Remote Procedure Call (RPC).

This part contains the following chapters:

Chapter 1, Setting up a ServerChapter 2, Sending and Receiving Datachapter 3,Making a Lobby to Gather Players TogetherChapter 4,Creating an Online Chat