The Essential Guide to Creating Multiplayer Games with Godot 4.0

Book description

Level up your Godot 4 networking skills with the only comprehensive multiplayer guide written by experienced game designer and developer, Henrique Campos, featuring dedicated servers and persistent worlds, illustrated with key images in color

Key Features

  • Ensure player synchronization and coexistence in a game world
  • Mitigate latency in your multiplayer games to design a seamless shared experience
  • Optimize and debug your games using profilers and monitors to visualize performance
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

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.

What you will learn

  • Understand the fundamentals of networking and remote data exchange between computers
  • Use the Godot game engine's built-in API to set up a network for players
  • Master remote procedure calls and learn how to make function calls on objects remotely
  • Enhance your GDScript proficiency to get the most out of this powerful language
  • Explore industry-standard solutions for common online multiplayer challenges
  • Improve your networking skills and discover how to turn single-player games into multiplayer experiences

Who this book is for

If you’re involved in game development with Godot and want to add multiplayer capabilities to enrich the shared gaming experience, then this book is for you. You’ll also find this book useful if you’re a network engineer looking to gain hands-on experience with practical projects. To get the most out of this book, a prior understanding of the Godot Engine design philosophy, the GDScript programming language, the SceneTree structure, and how nodes work is essential.

Table of contents

  1. The Essential Guide to Creating Multiplayer Games with Godot 4.0
  2. Foreword
  3. Contributors
  4. About the author
  5. About the reviewer
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Get in touch
    7. Share Your Thoughts
    8. Download a free PDF copy of this book
  7. Part 1:Handshaking and Networking
  8. Chapter 1: Setting up a Server
    1. Technical requirements
    2. Introduction to a network
    3. Understanding the ENetMultiplayerPeer class
      1. What is the ENet library?
    4. What is the UDP protocol?
    5. How does this connection happen?
      1. Creating the server
      2. Creating the client
      3. Testing our handshake
    6. Summary
  9. Chapter 2: Sending and Receiving Data
    1. Technical requirements
    2. Understanding packets
    3. Introduction to the JSON format
      1. Serialization
    4. Sending packets with PacketPeerUDP
      1. Creating an AuthenticationCredentials Autoload
      2. Sending players’ credentials
    5. Listening to packets with UDPServer
    6. Authenticating the player
      1. Loading a fake database
      2. Replying to the authentication request
      3. Maintaining the player’s session
    7. Loading the player’s avatar
    8. Summary
  10. Chapter 3: Making a Lobby to Gather Players Together
    1. Technical requirements
    2. Calling functions remotely with RPCs
      1. Introducing the @rpc annotation
      2. What’s necessary for an RPC?
    3. Understanding the multiplayer authority
    4. Comparing UDP and ENet approaches
    5. Remaking the login screen with RPCs
      1. Establishing an ENetMultiplayerPeer connection
      2. Creating the RPC functions template
      3. Authenticating the player
    6. Adding the player’s avatar
      1. Cleaning AvatarCards
    7. Retrieving players’ avatars
    8. Testing the lobby
    9. Summary
  11. Chapter 4: Creating an Online Chat
    1. Technical requirements
    2. Understanding data exchange and channels
      1. Reliable and unreliable packets
      2. Understanding channels
    3. Sending chat messages
    4. Updating peer’s data remotely
    5. Summary
  12. Part 2:Creating Online Multiplayer Mechanics
  13. Chapter 5: Making an Online Quiz Game
    1. Introducing the online quiz game
    2. Setting up a lobby for the quiz game
      1. Displaying new players
      2. Starting the match
    3. Implementing online turns
      1. Updating players about the round
    4. Turning local mechanics into remote gameplay
      1. Understanding the questions database
      2. Loading and updating questions
      3. Sending players’ answers to the server
    5. Summary
  14. Chapter 6: Building an Online Checkers Game
    1. Technical requirements
    2. Introducing the Checkers project
      1. Understanding the Checkers Piece scene
      2. Comprehending the FreeCell scene
      3. Introducing the CheckerBoard scene
    3. Serializing players’ turns
      1. Working with MultiplayerSynchronizer
      2. Updating and syncing the CheckerBoard
    4. Handling remote turn shifts
      1. Setting up players’ teams
      2. Enabling and disabling team pieces
    5. Managing win and lose conditions
    6. Summary
  15. Chapter 7: Developing an Online Pong Game
    1. Technical requirements
    2. Introducing the Pong project
      1. How the player paddles work
      2. Understanding the Ball scene
      3. Managing players’ scores
      4. Tying everything together
    3. Setting up online multiplayer paddles
      1. Changing the paddle’s owner
      2. Assigning the players’ paddles
    4. Syncing remote objects
      1. Updating the ball’s position
      2. Coordinating the paddle’s position
    5. Summary
  16. Chapter 8: Creating an Online Co-Op Platformer Prototype
    1. Technical requirements
    2. Introducing the platformer project
      1. Understanding the Player class
      2. Unveiling the Crate class
      3. How the InteractiveArea2D class works
      4. Understanding the PlayerSpawner class
    3. Spawning players in the match
      1. Giving players control in PlayerSpawner
      2. Setting up the Player multiplayer controls
    4. Syncing physical objects
      1. Synchronizing the player’s position and animations
      2. Updating the crate’s position remotely
    5. Summary
  17. Chapter 9: Creating an Online Adventure Prototype
    1. Technical requirements
    2. Introducing the prototype
      1. Understanding the Player scene
      2. Gauging the Asteroid scene
      3. Unraveling the quest system
      4. Breaking down the World scene
    3. Logging the player in to the server
      1. Authenticating players
      2. Syncing the World scenes
    4. Separating server and client responsibilities
      1. Shooting bullets on all instances
      2. Calculating an asteroid’s damage
    5. Storing and retrieving data on the server
      1. Implementing the quest system’s client side
      2. Implementing the quest system’s server side
    6. Summary
  18. Part 3:Optimizing the Online Experience
  19. Chapter 10: Debugging and Profiling the Network
    1. Technical requirements
    2. Introducing Godot’s Debugger
      1. Mastering the Stack Trace tab
      2. Debugging with the Errors tab
      3. Exploring the Profiler tab
      4. Exploring the Visual Profiler tab
      5. Exploring the Monitors tab
      6. Getting to know the Video RAM tab
      7. Grasping the Misc tab
    3. Understanding the Network Profiler
    4. Identifying the project’s bottlenecks
      1. Using the Network Profiler
      2. Using the Monitors tab
    5. Summary
  20. Chapter 11: Optimizing Data Requests
    1. Technical requirements
    2. Understanding network resources
    3. Decreasing the requests count
      1. Reducing the weapon fire count
      2. Decreasing Asteroid’s syncing count
    4. Compressing data with the ENetConnection class
    5. Summary
  21. Chapter 12: Implementing Lag Compensation
    1. Technical requirements
    2. Introducing lag issues
    3. Dealing with unreliable packets
    4. Common compensation techniques
      1. Implementing server-side motion
      2. Bridging the gaps with interpolation
      3. Playing ahead with prediction
      4. Gazing into the future with extrapolation
    5. Summary
  22. Chapter 13: Caching Data to Decrease Bandwidth
    1. Technical requirements
    2. Understanding caching
    3. Setting up the HTTPRequest node
      1. Understanding the HTTP protocol
      2. Setting up the scenes and database
    4. Implementing texture caching
    5. Implementing database caching
    6. Going further with caching
    7. Summary
  23. Index
    1. Why subscribe?
  24. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Download a free PDF copy of this book

Product information

  • Title: The Essential Guide to Creating Multiplayer Games with Godot 4.0
  • Author(s): Henrique Campos
  • Release date: December 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781803232614