Godot 4 Game Development Projects: Build five cross-platform 2D and 3D games using one of the most powerful open source game engines 2nd Edition -- - The 2025 ebook edition is available with updated content
Godot 4 Game Development Projects: Build five cross-platform 2D and 3D games using one of the most powerful open source game engines 2nd Edition -- - The 2025 ebook edition is available with updated content
com
OR CLICK HERE
DOWLOAD EBOOK
https://textbookfull.com/product/monogame-mastery-build-a-multi-
platform-2d-game-and-reusable-game-engine-jarred-capellman/
textbookfull.com
https://textbookfull.com/product/introducing-javascript-game-
development-build-a-2d-game-from-the-ground-up-1st-edition-graeme-
stuart/
textbookfull.com
https://textbookfull.com/product/introducing-javascript-game-
development-build-a-2d-game-from-the-ground-up-1st-edition-graeme-
stuart-2/
textbookfull.com
Beginning Swift Games Development for iOS: Develop 2D and
3D games Using Apple's SceneKit and SpriteKit 2nd Edition
James Goodwill
https://textbookfull.com/product/beginning-swift-games-development-
for-ios-develop-2d-and-3d-games-using-apples-scenekit-and-
spritekit-2nd-edition-james-goodwill/
textbookfull.com
https://textbookfull.com/product/practical-react-native-build-two-
full-projects-and-one-full-game-using-react-native-1st-edition-frank-
zammetti/
textbookfull.com
https://textbookfull.com/product/game-programming-in-c-
creating-3d-games-creating-3d-games-sanjay-madhav/
textbookfull.com
https://textbookfull.com/product/mostly-codeless-game-development-new-
school-game-engines-robert-ciesla/
textbookfull.com
Chris Bradfield
BIRMINGHAM—MUMBAI
Godot 4 Game Development Projects
Second Edition
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.
ISBN 978-1-80461-040-4
www.packtpub.com
To Priya, for being a constant source of support and encouragement.
To my students at the Science Academy STEM Magnet for being my guinea pigs, and for teaching me
how to be a better teacher.
-Chris Bradfield
Contributors
I would like to express my gratitude to Kenney Vleugels (@kenneyNL) for the 3D Minigolf tiles,
skorpio for the spaceship art, Luis Zuno (@ansimuz), and for Sunny Land art for their work.
About the reviewer
In the land of Indonesia, Isaiah Jamiel stands as a masterful artisan skilled in the realms of .NET and
Godot. Leading NTC Studios alongside Izra, Hansen, Sachio, Shannon, Della, and Yesika, he aspires
to achieve success in the realm of game development. Jamiel’s artistic talents extend beyond coding, as
he breathes new life into traditional Indonesian music with his arrangements. Yet amidst his passion
for code and music, his heart finds solace in the unwavering love he holds for his beloved Valerie and
his cherished family. Isaiah Jamiel’s unwavering commitment to blending innovation, artistry, and
profound connections serves as the driving force behind his remarkable endeavors in both the realm
of technology and the world of music.
Table of Contents
Prefacexiii
1
Introduction to Godot 4.0 1
General advice 2 Project Manager 7
The secret to learning effectively 3 Editor window 9
2
Coin Dash – Build Your First 2D Game 15
Technical requirements 16 Preparing for collisions 29
Setting up the project 16 Part 2 – the coin scene 31
Vectors and 2D coordinate systems 18 The node setup 32
Part 1 – the player scene 20 Coin script 32
Creating the scene 20 Part 3 – the Main scene 33
Sprite animation 21
Node setup 33
Collision shape 24
Main script 34
Scripting the player 25
Starting a new game 35
Moving the player 26
Choosing animations 28 Part 4 – the user interface 36
Starting and ending the player’s movement 28 Node setup 37
viii Table of Contents
3
Space Rocks: Build a 2D Arcade Classic with Physics 49
Technical requirements 50 The Main scene’s UI code 75
Setting up the project 50 Player code 76
4
Jungle Jump – Running and Jumping in a 2D Platformer 97
Technical requirements 98 Introducing kinematic bodies 100
Setting up the project 98 Collision response 100
Table of Contents ix
5
3D Minigolf: Dive into 3D by Building a Minigolf Course 143
Technical requirements 144 Understanding GridMaps 152
Introduction to 3D 144 Drawing the first hole 153
Environment and lighting 154
Orienting in 3D space 144
Adding the hole 155
Godot’s 3D editor 145
Adding 3D objects 146 Making the ball 157
Global versus local space 147 Testing the ball 157
Transforms147 Improving ball collisions 157
Meshes148
Cameras150
Adding UI 159
Aiming the arrow 159
Project setup 151 UI display 161
Creating the course 152
x Table of Contents
6
Infinite Flyer 179
Technical requirements 180 Increasing difficulty 195
Project setup 180 Collisions197
Fuel and score 199
Inputs180
7
Next Steps and Additional Resources 207
Using Godot’s documentation 208 Getting the export templates 213
Reading the API documentation 209 Export presets 214
Exporting215
Version control – using Git with Exporting for specific platforms 215
Godot210
Using Blender with Godot 211 Introduction to shaders 216
Import hints 211 Creating a 2D shader 218
Using blend files 212 3D shaders 222
Learning more 225
Exporting projects 212
Table of Contents xi
Index233
Chapter 6, Infinite Flyer, continues exploring 3D development, covering dynamic content, procedural
generation, and more 3D techniques.
Chapter 7, Next Steps and Additional Resources, covers even more topics to explore once you’ve
mastered the material in the five game projects. Look here for links and tips to further expand your
game development skills.
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file
extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “With
Godot 4, you have an additional option: importing .blend files directly into your Godot project.”
Preface xv
shader_type canvas_item;
void fragment() {
// Place fragment code here.
}
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words
in menus or dialog boxes appear in bold. Here is an example: “The first property is Shader, where
you can choose New Shader. When you do, a Create Shader panel appears.”
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at customercare@
packtpub.com and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen.
If you have found a mistake in this book, we would be grateful if you would report this to us. Please
visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would
be grateful if you would provide us with the location address or website name. Please contact us at
[email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you
are interested in either writing or contributing to a book, please visit authors.packtpub.com.
xvi
https://packt.link/free-ebook/9781804610404
General advice
This section contains some general advice to readers, based on the author’s experience as a teacher
and lecturer. Keep these tips in mind as you work through the book, especially if you’re very new
to programming.
Try to follow the projects in the book in order. Later chapters may build on topics that were introduced
in earlier chapters, where they are explained in more detail. When you encounter something that you
don’t remember, go back and review that topic in the earlier chapter. No one is timing you, and there’s
no prize for finishing the book quickly.
There is a lot of material to absorb here. Don’t feel discouraged if you don’t get it at first. The goal is
not to become an expert in game development overnight – that’s just not possible. Just like with any
other skill – carpentry or a musical instrument, for example – it takes years of practice and study to
develop proficiency. Repetition is the key to learning complex topics; the more you work with Godot’s
features, the more familiar and easier they will start to seem. Try repeating one of the earlier chapters
after you reach the end. You’ll be surprised at how much more you’ll understand compared to the
first time you read it.
If you’re reading this as an e-book, resist the temptation to copy and paste the code. Typing the code
yourself will engage your brain more actively. It’s similar to how taking notes during a lecture helps you
learn better than just listening, even if you never look back at the notes. If you’re a slow typist, it will
also help you work on your typing speed. In a nutshell: you’re a programmer, so get used to typing code!
One of the biggest mistakes that new game developers make is taking on a bigger project than they
can handle. It is very important to keep the scope of your project as small as possible when starting
out. You will be much more successful (and learn more) if you finish two or three small games than
if you have a large, incomplete project that has grown beyond your ability to manage.
You’ll notice that the five games in the book follow this strategy very strictly. They are all small in scope,
both for practical reasons – to fit reasonably into book-sized lessons – but also to remain focused
on practicing the basics. As you build the game, you will likely find yourself thinking of additional
features and gameplay elements right away. What if the spaceship had upgrades? What if the character
could do wall jumps?
Ideas are great, but if you haven’t finished the basic project yet, write them down and save them for
later. Don’t let yourself be sidetracked by one “cool idea” after another. Developers call this feature creep,
meaning a list of features that never stops growing, and it’s a trap that has led to many an unfinished
project. Don’t fall victim to it.
Finally, don’t forget to take a break now and again. You shouldn’t try and power through the whole
book, or even one project, in just a few sittings. After each new concept, and especially after each
chapter, give yourself time to absorb the new information before you dive into the next one. You’ll
find that you not only retain more information, but you’ll probably enjoy the process more.
What is a game engine? 3
• Rendering (2D and 3D): Rendering is the process of displaying the game on the player’s screen.
A good rendering pipeline must take into account modern GPU support, high-resolution
displays, and effects such as lighting, perspective, and viewports, all while maintaining a very
high framerate.
4 Introduction to Godot 4.0
• Physics: While a very common requirement, building a robust and accurate physics engine is
a monumental task. Most games require some sort of collision detection and response system,
and many need physics simulations, but few developers want to take on the task of writing
one - especially if they have never tried to do so before!
• Platform support: In today’s market, most developers want to be able to release their games
on multiple platforms, such as desktops, consoles, mobile, and/or the web. A game engine
provides a unified exporting process to publish games on multiple platforms without needing
to rewrite game code or support multiple versions.
• Common development environment: By using the same unified interface to make multiple
games, the developer doesn’t have to re-learn a new workflow every time they start a new project.
In addition to these, there will be tools to assist with features such as networking, easing the process of
managing images and sound, animations, debugging, and many more. Often, game engines will include
the ability to import content from other tools, such as those used to create animations or 3D models.
Using a game engine allows the developer to focus on building their game rather than creating the
underlying framework needed to make it work. For small or independent developers, this can mean the
difference between releasing a game after one year of development instead of three, or even never at all.
There are dozens of popular game engines on the market today, such as Unity, Unreal Engine, and
GameMaker Studio, just to name a few. An important fact to be aware of is that the majority of popular
game engines are commercial products. They may or may not require any financial investment to
get started, but they will require some kind of licensing and/or royalty payments if your game makes
money. Whatever engine you choose, you need to carefully read the user agreement and make sure
you understand what you are and are not allowed to do with the engine, and what hidden costs, if
any, you may be responsible for.
On the other hand, some engines are non-commercial and open source, such as the Godot game
engine, which is what this book is all about.
What is Godot?
Godot is a fully featured modern game engine, providing all of the features described in the previous
section and more. It is also completely free and open source, released under the very permissive
MIT license. This means there are no fees, no hidden costs, and no royalties to pay on your game’s
revenue. Everything you make with Godot 100% belongs to you, which is not the case with many
commercial game engines that require an ongoing contractual relationship. For many developers,
this is very appealing.
If you’re not familiar with the concept of open source, community-driven development, this may seem
strange to you. However, much like the Linux kernel, Firefox browser, and many other very well-known
pieces of software, Godot is not developed by a company as a commercial product. Instead, a dedicated
Downloading Godot 5
community of passionate developers donates their time and expertise to building the engine, testing
and fixing bugs, producing documentation, and more.
As a game developer, the benefits of using Godot are many. Because it is unencumbered by commercial
licensing, you have complete control over exactly how and where your game is distributed. Many
commercial game engines restrict the types of projects you can make or require a much more expensive
license to build games in certain categories, such as gambling.
Godot’s open source nature also means there is a level of transparency that doesn’t exist with commercial
game engines. For example, if you find that a particular engine feature doesn’t quite meet your needs,
you are free to modify the engine itself and add the new features you need, with no permission
required. This can also be very helpful when debugging a large project because you have full access
to the engine’s internal workings.
It also means that you can directly contribute to Godot’s future. See additional topics in Chapter 7 for
more information about how you can get involved with Godot development.
Now that you have an understanding of what Godot is and how it can help you build a game, it’s time
to get started. In the next section, you’ll see how to download Godot and set it up for use on your
own computer.
Downloading Godot
You can download the latest version of Godot by visiting https://godotengine.org/ and
clicking Download Latest. This book is written for version 4.0. If the version you download has another
number at the end (such as 4.0.3), that’s fine – this just means that it includes updates to version 4.0
that fix bugs or other issues.
On the download page, you will also see a standard version and a .NET version. The .NET version is
specially built to be used with the C# programming language. Don’t download this one unless you
plan to use C# with Godot. The projects in this book do not use C#.
Unzip the downloaded file, and you’ll have the Godot application. Optionally, you can drag it to your
Programs or Applications folder, if you have one. Double-click the application to launch it and
you’ll see Godot’s Project Manager window, which you’ll learn about in the next section.
• Steam: If you have an account on Steam, you can install Godot via the Steam desktop application.
Search for Godot in the Steam store and follow the instructions to install it. You can launch
Godot from the Steam application:
• Itch.io: You can also download Godot from the popular itch.io website. Itch is a marketplace
for independent game developers and creators. Search for Godot and download it from the
provided links.
• Package Managers: If you’re using one of the following operating system package managers, you
can install Godot via its normal installation process. See the documentation for your package
manager for details. Godot is available in these package managers:
Homebrew (macOS)
Scoop (Windows)
Snap (Linux)
Overview of the Godot UI 7
Congratulations, you have successfully installed Godot on your computer. In the next section, you
will see an overview of Godot’s editor interface – the purposes of the various windows and buttons
you’ll use when working with the editor.
Project Manager
The Project Manager window is the first window you’ll see when you open Godot:
In this window, you can see a list of your existing Godot projects. You can choose an existing project
and click Run to play the game or Edit to work on it in the Godot editor. You can also create a new
project by clicking New Project:
Here, you can give the project a name and create a folder to store it in. Note the warning message – a
Godot project is stored as a separate folder on the computer. All the files that the project uses must
be located in this folder. This makes it convenient to share Godot projects because you only need to
zip the project folder and you can be confident that another Godot user will be able to open it and
not be missing any necessary data.
Renderer
When creating a new project, you also have the choice of Renderer. The three options represent the
balance between advanced, high-performance graphics that require a modern desktop GPU, and
compatibility with less-capable platforms such as mobile and older desktops. You can change this option
later if you need, so it’s OK to leave it as the default setting. If you later decide to build games for the
mobile platform, the Godot documentation has a great deal of information regarding performance
and rendering options. See Chapter 7 for links and more information.
Choosing filenames
When you’re naming your new project, there are a few simple rules you should try and follow that may
save you some trouble in the future. Give your project a name that describes what it is – Wizard Battle
Arena is a much better project name than Game #2. In the future, you’ll never be able to remember
which game number two was, so be as descriptive as possible.
Overview of the Godot UI 9
You should also think about how you name your project folder and the files in it. Some operating
systems are case-sensitive and distinguish between My_Game and my_game, while others do not.
This can lead to problems if you move your project from one computer to another. For this reason,
many programmers develop a standardized naming scheme for their projects, such as not using spaces
in filenames and using _ between words. Regardless of what naming scheme you adopt, the most
important thing is to be consistent.
Once you’ve created the project folder, the Create Edit button will open the new project in the editor
window. Try it now: create a project called test_project.
Console window
If you’re using a version of the Windows operating system, you’ll also see a console window
open when you run Godot. In this window, you can see warnings and errors produced by the
engine and/or your project. This window doesn’t appear on macOS or Linux, but you can see the
console output if you launch the application from the command line using a Terminal program
Editor window
The following figure is a screenshot of the main Godot editor window. This is where you will spend most
of your time when building projects in Godot. The editor interface is divided into several sections, each
offering different functionality. The specific terminology for each section is described after Figure 1.5:
The main portion of the editor window is the Viewport. This is where you’ll see the parts of your game
as you’re working on them.
10 Introduction to Godot 4.0
In the top center of the window is a list of the Workspaces you can switch between when working on
different parts of your game. You can switch between 2D and 3D mode, as well as Script mode, where
you’ll edit your game’s code. AssetLib is a place where you can download add-ons and example projects
contributed by the Godot community. See Chapter 7 for more information about using the asset library.
Figure 1.6 shows the toolbar for the current workspace you’re using. The icons here will change based
on what kind of object you’re working with:
The buttons in the upper-right playtest area are for launching the game and interacting with it when
it’s running:
On the left and right sides are the Docks or Tabs you can use to view and select game items and set
their properties. On the bottom of the left-hand dock, you’ll find the FileSystem tab. All the files in the
project folder are shown here, and you can click on folders to open them and see what they contain.
All resources in your project will be located relative to the res:// path, which is the project’s root
folder. For example, a file path might look like this: res://player/player.tscn. This refers
to a file in the player folder:
Language: English
Credits: Produced by Josep Cols Canals, Chuck Greif and the Online
Distributed Proofreading Team at http://www.pgdp.net
(This
file was produced from images generously made available
by The Internet Archive/Canadian Libraries)
P HIL IP II. OF S PA IN
BY
MARTIN A. S. HUME
EDITOR OF
THE ‘CALENDAR OF SPANISH STATE PAPERS OF ELIZABETH’
(PUBLIC RECORD OFFICE)
Sepulveda.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com