Godot Game Development For Beginners (099 198)
Godot Game Development For Beginners (099 198)
Here's what the MoveDown animation will look like. Click on the New Animation button to
create a new animation.
Go through now and create all of the idle and move animations. Once that's done, select
the AnimatedSprite node and...
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
• Set the Animation to IdleDown
• Enable Playing
Back in the Player script, let's create a new variable to reference the animated sprite node.
Then we can create the manage_animations function which will check the velocity and facing
directions to determine which animation to play.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
The play_animation function will take in an animation name and play that.
We can call the manage_animations function every frame at the end of the _physics_process
function.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Now when we press play, you should see that the animations play when we move around.
In the MainScene, create a new child node of type TileMap. Then in the inspector, create a
new tileset.
These tile sets require tiles, so to do this, we need to create a new scene with all the available
tiles in it.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Once all the tiles are in the new scene, go to Scene > Convert To... > Tile Set and save it as
tileset.tres.
Back in the MainScene, select the TileMap node and in the inspector, select the tileset property
and choose load. Select the resource we just made and the tiles should appear in the panel to
the right.
We can now select a tile and paint it in the scene view. Here are some keys for building your
tilemap:
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
• Place tile - Left Mouse
• Delete tile - Right Mouse
• Draw line - Shift + Left Mouse
• Draw rectangle - Shift + Ctrl + Left Mouse
• Delete line and delete rectangle are the same but with right mouse
Now if we try to place a tree, you'll see that it replaces the tile rather than placing it on top. To fix
this, we can create a second tilemap.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Something you might also want is a collision with some tiles. To implement this, select the
tilemap in the file system and the TileSet panel should pop up.
• Select a tile
• Click on the sprite that pops up (a bunch of settings should then appear)
• Select Collision
• Select the Rectangle tool
• Draw the collider on the sprite
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Let's now create a larger scene with our two tilemaps.
Continued in Part 2
With the tilemap created and player set up, we now have the basis for a spectacular 2D RPG in
Godot! Over the course of part 1, we've covered not only setting up sprite animations for your
player character in Godot, but also setting up raycasts and tilemaps with appropriate
collisions. Fortunately, with just these foundations, you can expand into other games as well, or
create even more complicated RPG maps.
Nevertheless, our RPG certainly isn't complete! In Part 2, we'll cover the rest of our RPG
creation process with enemies, loot, UI systems, and more! Hope to see you then!
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Build a 2D RPG in Godot - Part 2
Introduction
Welcome back everyone! It's time to finish our 2D RPG in Godot!
For Part 1 of this tutorial series, we started setting up our 2D RPG project in the open-source
and free Godot game engine. Some of the things we learned about include: tilemaps, player
controllers, raycasting, sprite animations, and more! All in all, we have a great base to work
with and expand on!
However, what's an RPG without some enemies or items to loot? In this second part of our 2D
RPG tutorial for Godot, we'll finish by adding these elements, as well as adding the ability for
our camera to follow the player.
So sit back, and prepare yourself to finish your first RPG in Godot!
Project Files
For this project, we'll be needing some assets such as sprites and a font. These will be sourced
from kenney.nl and Google Fonts. You can, of course, choose to use your own assets, but for
this course we'll be using these.
Camera Follow
With our big scene, there's one problem which is the fact that the camera doesn't move. To fix
this, let's create a new Camera2D node in the MainScene.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Then we can create a new script attached to the camera node. Call it CameraFollow. All we're
going to do here is find the player and move towards them every frame.
Finally, in the inspector make sure to enable Current so that the camera will be the one we look
through.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Now if we press play, you'll see that the camera follows the player.
Creating an Enemy
Let's now create an enemy scene. These will chase after the player and attack them when in
range.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Scripting the Enemy
On the enemy node, create a new script called Enemy. We can start with the variables.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Inside of the _physics_process function (gets called 60 times per second) we want to move
towards the target if we're further than the attack distance but closer than the chase distance.
Back in the MainScene let's drag in the Enemy scene to create a new instance. Now we can
press play and test it out. The enemy should move towards us.
Now that the enemy moves towards us, let's have it attack us.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
1. Go to the Enemy scene
2. Select the Timer node
3. In the Inspector panel, click on the Node tab
4. Double click on the timeout() signal
5. Click Connect
This will create the _on_Timer_timeout function. Here, we want to check if we're within the
attack distance and then attack the target. We'll be creating the take_damage function on the
player soon.
In the _ready function which gets called once the node is initialized, let's setup the timer node.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Finally for the enemy, let's create the take_damage and die functions. The target.give_xp
function will be called over on the player script later on.
Player Functions
Now we want to go over to the Player script and add in some new functions to work with the
enemies. Let's start with the give_gold function which will add gold to the player.
For the levelling system, let's create the give_xp and level_up functions.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
The take_damage and die functions will be called when an enemy attacks us.
Now if we press play, you'll see that the enemy can attack and kill us - which will reload the
scene.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Player Interaction
With our player, we want the ability to interact with chests and enemies. In the Player script,
let's create the _process function (called every frame) and check for when we're pressing the
interact button.
The try_interact function will check to see if the raycast is hitting anything. If it's an enemy,
damage them but if it's not - call the on_interact function if they have it.
Chest Interactable
Now we need something to interact with. This is going to be a chest which will give the player
some gold. Create a new scene with a root node of Area2D.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Next, create a new script called Chest attached to the Area2D node. All we're going to do here,
is have the on_interact function which gives the player gold then destroys the node.
You might notice that interacting with the chest wont work but attacking the enemy does work.
So in the Player scene, select the ray cast node and enable Collide With Areas.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Creating the UI
Create a new scene with a root node of Control.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
As a child of this BG node, we want to create three new nodes.
• LevelBG - TextureRect
• HealthBar - TextureProgress
• XpBar - TextureProgress
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Now we need to setup our fonts. With the assets we imported into the project, we have two font
files. Right now, these are just .ttf files which need to be converted in a format that Godot can
read. For each font file...
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
As a child of the LevelBG node, create a new Label node and rename it to LevelText.
Scripting the UI
Next up, let's create a new script attached to the UI node, called UI. We'll start with the variables
to reference the children nodes.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Then we have our functions which update each of these nodes.
Now that we have the UI script, let's go over to the MainScene and drag the UI scene in. To
make it render to the screen, we need to create a CanvasLayer node and make UI a child of it.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
In order to be able to access the UI script for the player, we need to move the canvas layer up
to the top of the hierarchy.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Over in the Player script, let's create a variable to reference the UI script.
Create the _ready function which gets called once the node is initialized. In there, we'll be
initializing the UI.
Now we need to go through a few functions and call the UI functions at the end of them. They
go as following:
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
We can now press play and see that the UI is set at the start of the game and changes as we
get gold, take damage, get xp and level up.
With all of this, we're finished with our RPG game in Godot. Let's now go back to
the MainScene and place some enemies and chests around the place.
Conclusion
Congratulations on completing the tutorial! Through perseverance, hard work, and a little bit of
know-how, we just created a 2D RPG in Godot with a number of different features. Over the
course of Part 1 and Part 2, we've shown you how to set up:
And with that, you should now possess the fundamental skills to create even more RPGs in the
future! Of course, you can expand upon the game created here - adding in new features,
fleshing out current ones, or even just improving certain aspects you felt were lacking! There
are endless directions to go from here, but with this solid foundation, you'll have quite the
headstart!
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Thank you very much for following along, and I wish you the best of luck with your future games.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Develop a 3D Action RPG in Godot - Part 1
Introduction
Ready to create your own game with some action-oriented gameplay?
In some of our previous tutorials, we covered making a 3D FPS and a 2D RPG. Both are well-
loved genres in the gaming industry and have a lot to offer players in terms of entertaining
experiences. However, what if you wanted a 3D RPG or maybe something with a little more
spice to it? For this tutorial, we're going to delve into just that and show you how to make a 3D,
action RPG in the Godot game engine.
This 3D action RPG tutorial will cover a lot of ground, including how to make:
If that sounds great to you, we hope you sit back and are eager to create your own action RPG
from scratch!
Before starting, please note that this tutorial won't be going over the basics of Godot. If this is
your first time learning the engine, make sure to check out the introductory tutorial first.
Want to jump straight to making enemies and combat? You can try out Part 2 instead!
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Project Files
In this course, we're going to be using a few models and a font to make the game look nice. You
can, of course, choose to use your own, but we're going to be designing the game with these
specific ones in mind. The models are from kenney.nl, a good resource for public-domain game
assets. Then we're getting our font from Google Fonts.
Project Setup
To begin, let's create a new Godot project. First, we're going to import the assets we'll need.
In the scene panel, select 3D Scene as our first root node. Rename the node to MainScene
and save it to the file system.
You'll see that we're in 3D mode here. In 3D, we have Spatial nodes. These are like Node2D's,
but allow us to position, rotate and scale them in 3D space. Below you'll see we have a few
different colored lines.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Creating Our Environment
Here in the MainScene, we're going to start off by creating our environment.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
This is going to be our ground but we have one problem. There's no collider on the model so
we're going to fall through it. To do this quickly, we can...
Now that we have the ground, let's drag in the naturePack_019.obj model.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
We can then drag in more models, assign colliders to them and scale/position the nodes to
create a nice looking environment.
One thing you might notice is that the hierarchy is looking quite cluttered with all of these
models. To fix this, we can create a new Node node and drag the models in as a child. This is
the most simplistic type of node and is good for containers. We can then retract and expand the
node when we need to.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Another thing you may notice is that it's quite dark. To fix this, we can create
a DirectionalLight node which acts as our sun.
Along with this, let's make the skybox look a bit nicer. Double click on the default_env.tres
resource in the FileSystem to open up the options in the inspector.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Creating the Player
Create a new scene with a root node of KinematicBody. This is a node for physics objects you
want to walk around like a player or enemy.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
For the camera, we're going to have a center node with the camera as the child.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
For the sword, we're going to create a Spatial node called WeaponHolder. This will hold the
sword model.
For when we want to attack enemies, we'll need to create a RayCast node. Rename it to
AttackRayCast. This shoots a point from a certain position in a direction and we can get info on
what it hits.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Back in the MainScene, let's drag in the Player scene.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Camera Look
Now that we've got our player object, let's start to script the camera look system. In the Player
scene, select the CameraOrbit node and create a new script called CameraOrbit. We can start
with the variables.
The _input function gets called when any input is detected (keyboard, mouse key, mouse
movement, etc). We want to check if the mouse moved, and if so - set the mouse delta.
Inside of the _process function (called every frame), we're going to rotate the camera vertically
and rotate the player horizontally. Rotating the player separately makes it easier later on to
figure out movement directions.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Finally, we can lock and hide the mouse cursor in the _ready function.
Now if we press play, it's going to ask us to select a base scene. Choose the MainScene then
we can test out the camera orbit system.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Now we're going to be detecting keyboard inputs and basing the movement on that. In order to
get these inputs though, we need to create actions. Let's go to the Project Settings window
(Project > Project Settings...) then go to the Input Map tab.
Here, we want to enter in an action name and add it. Then assign a key to that action. We need
6 different actions.
• move_forwards
o Key = W
• move_backwards
o Key = S
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
• move_left
o Key = A
• move_right
o Key = D
• jump
o Key = Space
• attack
o Mouse Button = Left Button
Back in our script, we can create the _physics_process function. This is built into Godot and
gets called 60 times a second - this is good for doing physics calls.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Inside of this function, we're first going to reset the x and z axis' of our velocity vector and create
a new vector to store our inputs.
Then we can detect our movement actions and modify the input vector.
With our input vector, we want to normalize it. This means resizing the vector to a magnitude (x
+ y + z = magnitude) of 1. Because when we move forward, our input vector is (0, 0, 1) with a
magnitude of 1. Yet when we move diagonally (1, 0, 1) we have a magnitude of 2. We move
faster diagonally, so reducing our diagonal input vector to something like (0.5, 0, 0.5) will
maintain a magnitude of 1.
Now since we can look around and rotate, we don't want to move along the global direction. We
need to find our local direction.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Next, we can apply this to our velocity vector.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Gold Coins
Next up, we're going to create a coin object which the player can collect.
Attached to the Area node, create a new script called GoldCoin. First, we can work on our two
variables.
Inside of the _process function which gets called every frame, we'll rotate the coin along its Y
axis.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
In order to detect when the player has entered the coin, we need to connect to a signal.
This function gets called when another body enters the coin collider. What we want to do is
check to see if the body is the player. If so, call the give_gold function (which we'll create after)
and then destroy the node with queue_free.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Let's now create the give_gold function over in the Player script.
Back in our MainScene, let's drag in the GoldCoin scene. Duplicate it multiple times to create a
number of different instances and position them around.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Just like with the models, let's create a new empty Node and make the coins a child of it. This
will act as a sort of container to make the scene hierarchy less cluttered.
Continued in Part 2
So far, we've created a player with a sword, scripted our player to move, and even set up our
various coins that the player will try to collect. To boot, we also set up our camera so that it can
follow the player. While some aspects certainly are playable in this state, our 3D action RPG is
definitely not complete! After all, what is an RPG without some enemies and obstacles to face
off against?
In Part 2, we'll finish up this 3D action RPG project by setting up our enemies, animating our
sword for combat, and implementing our UI. In so doing, we'll have a solid foundation for an
RPG that can be expanded upon as you wish! Until the next part!
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Develop a 3D Action RPG in Godot - Part 2
Introduction
Welcome back to this tutorial series where we're building a 3D action RPG from scratch with
Godot. In Part 1, we covered a lot of ground with how to make an action RPG with Godot,
including:
While these elements certainly create a great foundation for our game, we'll want to add just a
bit more to create that true, action RPG feel. Thus, in Part 2, we'll be finishing our project by
adding enemies and combat mechanics - including a nifty animation for our sword. To boot,
we'll also dive into the Godot UI so that you can set up a simple way to track the player's health
and gold.
We hope you're ready to dive in and create this impressive piece for your portfolio!
Project Files
In this course, we're going to be using a few models and a font to make the game look nice. You
can, of course, choose to use your own, but we're going to be designing the game with these
specific ones in mind. The models are from kenney.nl, a good resource for public-domain game
assets. Then we're getting our font from Google Fonts.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
7. Set the Transform > Translation to 0, 1.25, 0
8. Set the Transform > Rotation Degrees to 90, 0, 0
Let's differ this capsule from our player. Just under where we set the radius. we can create a
new SpatialMaterial. Click on that to open up the material properties.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Next, we can create a CollisionShape node with the same properties as the mesh.
Finally, we're going to create a Timer node which can send out a signal every certain amount of
seconds. This will be setup in-script.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Scripting the Enemy
Now, we're going to create the enemy script. Select the Enemy node and create a new script
called Enemy. First, we want to enter in our variables.
First, we're going to create the _ready function which gets called once the node is initialized.
Inside of here, we're going to set the timer wait time and start it.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
But nothing will happen right now because the timer isn't connected to anything. So select the
node and in the Node tab, we want to connect the timeout() signal to the script.
With the new function, let's check our distance to the player and damage them. We'll create the
take_damage function on the player soon.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Next, let's implement the ability for the enemy to chase after the player when further than the
attack distance.
Let's finish of the enemy script with the take_damage and die functions. The take damage
function will be called when the enemy is attacked by the player.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Our enemy is now finished. We've got all the functions setup, so let's now go over to the Player
script and create the functions which get called by an attacking enemy.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
We can now go to the MainScene and drag the enemy scene in to create a new instance.
Press play and the enemy should chase after you.
Sword Animation
Now its time to implement the ability to attack enemies. Before we jump into scripting, let's
create an animation for the player's sword. In the Player scene, right click on
the WeaponHolder and create a new child node of type AnimationPlayer. Rename it
to SwordAnimator.
Selecting the node should toggle the Animation panel at the bottom of the screen. Here, we
want to click on the Animation button and create a new animation called attack.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
With the animator, we can choose which properties we want to animate. Select the
WeaponHolder, and in the inspector select the key icon next to Rotation Degrees. Create that
new track.
By default the FPS of the animation is quite low, so select the Time drop-down and change that
to FPS. Set the FPS to 30.
Now we can right-click on the tack and insert a new key. Selecting the key, we can change the
rotation with the Value property.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Here's the attack animation I made.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Attacking the Enemy
Now that we have the attack animation, let's go ahead and start scripting it. In the Player script,
let's create the _process function which gets called every frame.
The try_attack function will check to see if we can attack and if so, damage the enemy.
First, we want to see if we can attack based on the attack rate. We're getting the current time
elapsed in milliseconds. That's why we're multiplying attackRate by 1000.
Then we want to set the last attack time and play the animation.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
To actually attack the enemy, we need to check to see if the raycast is detecting an enemy.
We can now press play and test it out. Try attacking the enemy and eventually they should
disappear, showing that our system works.
Creating the UI
Now that we have all of the systems in place, the final thing to do is implement the user
interface. This will include a health bar and gold text. So to begin, let's create a new scene of
type user interface (Control node). Rename it to UI and save the scene.
As a child, create a new TextureProgress node. This is a texture which can resize like a
progress bar.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
1. Rename the node to HealthBar
2. Enable Nine Patch Stretch
3. Set the Under and Progress textures to UI_WhiteSquare.png
4. Set the Under tint to dark grey
5. Set the Progress tint to red
6. Bring the anchor points (4 green pins) down to the bottom left of the screen
7. Drag the health bar down to the bottom left and resize it (drag on the circles to resize)
For our gold text, we're going to need a font as the default one isn't that versitile.
1. Right click on the .ttf file in the file system and select New Resource...
2. Search for and select DyanamicFont
3. This will create a new dynamic font resource
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Double click the dynamic font, and in the inspector...
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Now we can create a Label node and rename it to GoldText. This node will display text on-
screen.
Now that we have our UI, let's go to the Player scene and create a child node
called CanvasLayer. This is a node which renders the control node children to the screen. So
as a child of the canvas layer, drag in the UI scene.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
If we press play, you'll see that the UI is rendering on the screen.
Scripting the UI
We've got our UI displaying on-screen, but it doesn't do anything just yet. In the UI scene,
create a new script attached to the UI node called UI. We can start with the variables.
Then we can create the update_health_bar function. This will set the value of the texture
progress.
Finally, the update_gold_text function will update the text of the gold text label.
Now that we've got the UI script created, let's go to the Player script and hook these functions
up.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Then inside of the _ready function (called when the node is initialized), we want to initialize the
UI.
And there we go. You can press play now and see that the UI will update when we take damage
and collect coins.
Conclusion
Congratulations on completing the tutorial! If you've been following along, you should now have
a 3D action RPG playable within your Godot editor! Over the course of both Part 1 and Part 2,
we learned how to create:
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
With that, you now have a fantastic project that you can share with your friends, add to your
portfolio, or use as a base for your own projects. As you can imagine, these systems can be
expanded in numerous ways, such as adding more collectibles, adding different enemies, and
beyond. We encourage you to explore what Godot is capable of - but for now, we hope you
enjoy this action RPG you've created with your own two hands!
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Make a Strategy Game in Godot - Part 1
Introduction
Whether turn-based, real-time, or resource management based, strategy games remain
cemented in the world as one of the most popular genres. This is why numerous beginning and
experienced developers alike dream of creating their own strategy games and building a
balanced, challenging gameplay experience. So, what if we told you that making your own
strategy game was completely possible with Godot?
If that sounds exciting, then this is the tutorial for you! Through this tutorial, we're going to show
you how to make a resource-based city building game with ease - all within the Godot game
engine. You will learn several features common to strategy games such as:
So, if you're ready, buckle down, turn on your computer, and get pumped to make a strategy
game project with Godot.
Before we begin though, it's important to know that this tutorial will not go over the basics of
Godot. If you're new to the engine, we recommend you read through our introductory tutorial on
the subject!
Already know all this and want to jump into building placement and turn-based game flow? Try
out Part 2 instead!
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Project Files
In this tutorial, we'll be using some sprites from the kenney.nl website (an open domain game
asset website) and fonts from Google Fonts. You can of course choose to use your own assets,
but we'll be designing the game around these:
Let's also import our assets by dragging the two folders into the file system.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Something we also want to do is change the resolution of the screen. When we press play
(you'll be asked to choose a base scene - select the MainScene), you'll see that the screen is
pretty small. Due to our sprite size and the amount of tiles we're going to have, let's set the
resolution.
Open the Project Settings window (Project > Project Settings...) and go down to the Display >
Window tab.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Creating the Tiles
We're going to start by creating the tile scene. This will contain the sprite, highlight, collider,
script, etc. So create a new scene with a root node of Area2D. An Area2D node can detect
collisions which is needed for selecting tiles later on.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
We then want to create a few more nodes as a child of the main node.
1. Drag in the Ground.png image to create a new Sprite node (make sure it's at a position
of 0, 0)
2. Drag in the TileHighlight.png image to create a new Sprite node
a. Rename it to Highlight
b. Set the Scale to 6.4, 6.4
c. Click the eye to disable it by default
3. Create a new Sprite node
a. Rename it to BuildingIcon
4. Create a new CollisionShape2D node
a. Set the Shape to RectangleShape2D
b. Set the Extents to 32, 32
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Back in the MainScene, let's drag in the Tile scene to create a new instance. To make it easier
to position, enable Grid Snapping.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
With the tile node selected, press Ctrl + D to duplicate it. Fill in a 20 by 9 area with tiles. This is
going to be where we play the game and make sure that it's all contained within the blue box
(the window).
You may notice that the scene hierarchy is pretty cluttered. We have over 100 nodes which will
make it harder to find other things that aren't tiles. In order to fix this, we can...
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
We haven't created the script for the tile yet, but next up is the UI.
Creating the UI
Our UI is going to be a bar at the bottom of the screen displaying our resources, turn and
buttons. Create a new scene with a root node of type User Interface (Control node).
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
As a child of the UI node, create a ColorRect node. This is a control node that renders a certain
color.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Before we continue, let's setup out fonts. In the Font folder, we have two .ttf files. For each font
file...
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Next, create a Button node and rename it as EndTurnButton.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Create a new Label node and rename it to TurnText.
Next, we'll be creating the three building buttons. We're going to store these inside of a node
which can automatically resize its children. Create a new HBoxContainer node and rename it
to BuildingButtons.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
As a child of the BuildingButtons node, create three Button nodes. You'll see that they
automatically resize to fit the bounds of the BuildingButtons node.
• MineButton
• GreenhouseButton
• SolarPanelButton
For each button, set their Icon texture to their respective texture in the Sprites folder.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Create a new Label node and rename it to HeaderFoodMetal.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Select the two labels and duplicate them. Rename them respectively to:
• HeaderOyxgenEnergy
• OxygenEnergyText
Move them over to the right. Change the text of the header label to 'Oxygen: Energy:'.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
There we go. Our UI is now complete, so let's go back to the MainScene and drag in the UI
scene.
Now if we press play, you'll see basically what the final game will look like - just without the
functionality.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Tile Script
To begin scripting, we'll create the Tile script. This will hold data and functions relative to each
tile. In the Tile scene, select the Tile node and create a new script attached to it called Tile.
We'll start with our variables.
Next, let's create the _ready function - this gets called when the node is initialized. Here, we're
going to add the tile to the "Tiles" group. A group in Godot can allow us to easily access and
modify a group of nodes.
The toggle_highlight function will toggle the highlight visual on or off, also toggling whether or
not a building can be placed.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
The place_building function gets called when we place a building on the tile.
Next, we need to connect a signal to the script. The input_event signal gets emitted once an
input is detected in the collider like a mouse click. So with the Tile node selected, go to
the Node panel and double click the signal. Then connect it to the script.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
This will create the _on_Tile_input_event function in the script. We need some other things
implemented first, so let's just add pass to the function which means it's empty.
Map Script
The Map script will reference all our tiles and have the ability to highlight the available ones, get
a tile at a given position, etc. In the MainScene, select the Tiles node and attach a new script
called Map. We can start with our variables.
The get_tile_at_position function will return the tile that is at the given position.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
The disable_tile_highlights function loops through all the tiles and disables their highlight
visual.
The highlight_available_tiles function will highlight all of the tiles which can have a building
placed on. This is the surrounding tiles of all buildings. First, we're going to loop through all tiles
that have a building on it.
Inside the for loop, we're first going to get the north, south, east and west tile relative to the
current one.
After this, we're going to check each of the tiles. If they're not null, enable the highlight.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
We're not finished with the Map script yet, but we do need to work on a few other things first.
BuildingData Script
The BuildingData script isn't a script which is attached to a node. This is going to be a global
class which can be accessed anywhere in the project. In the Script tab, go File > New Script...
and create a new script called BuildingData.
Then we need to go to the Project Settings (Project > Project Settings...) and click on
the AutoLoad tab.
Back in the BuildingData script, let's begin by creating a new class called Building. This is
going to be an object to hold the data for each building.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
We're using integers for the building type and resources. These integers refer to a specific thing.
Building Types
• Base = 0
• Mine = 1
• Greenhouse = 2
• Solar Panel = 3
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Resources
• None = 0
• Food = 1
• Metal = 2
• Oxygen = 3
• Energy = 4
Outside of the Building class, we can create 4 variables for each of our 4 buildings (Base, Mine,
Greenhouse, Solar Panel).
We'll be using these variables to know what each building produces, takes, the texture and
other values.
Continued in Part 2
While there are certainly more elements to add, we've gone on quite the journey here so far! As
the basis of our game, we've already set up a grid-based tile system that will allow us to place
buildings later and highlight tiles where applicable buildings can be played. Additionally, we've
also set up the buildings themselves which will provide the crucial resource management
functionality to our game (along with an accompanying UI).
While this is a great start in building a strategy game with Godot, we have a bit more to go! In
Part 2, we're going to finish off our map, create the ability to place the buildings, create the turn-
based gameplay flow, and beyond to connect all our features up to work as one, coherent game
project! See you then!
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Make a Strategy Game in Godot - Part 2
Introduction
Welcome back to Part 2 of creating a strategy game in the Godot game engine!
In Part 1, we began showing you how to build your first strategy game in Godot by setting up
highlight-able tiles, buildings, and the basic UI which will tell the players crucial information
about their resource management. All in all, we have a great foundation to work with so we can
finish our project and add it to our portfolio!
Of course, with this being Part 2, there is still more go. We need to finish up our map system,
set up our UI properly, give ourselves the ability to place buildings, and even implement the
overall turn-based gameplay flow. So, if you're prepared, and let's finish this resource
management game and become master Godot developers!
Project Files
In this tutorial, we'll be using some sprites from the kenney.nl website (an open domain game
asset website) and fonts from Google Fonts. You can of course choose to use your own assets,
but we'll be designing the game around these:
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Finally, the _ready function gets called when the node is initialized. Here, we want to get all of
the tiles in the "Tiles" group and setup the initial base building.
Back in the MainScene, let's select the center tile and enable Start Tile.
Now if we press play, you should see that the center tile has a Base building on it.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
GameManager Script
The GameManager script is what's going to manage our resources and states. Go to
the MainScene and select the MainScene node. Create a new script attached to it
called GameManager. We can start with our variables.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
The on_select_building function gets called when we press one of the three building UI
buttons. This will be hooked up later on when we create the UI script.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
The add_to_resource_per_turn function adds the given amount to the given resource per turn.
The place_building function will be called when we place down a tile on the grid.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Finally, we have the end_turn function which gets called when we press the end turn button.
Okay so we've got our GameManager class all setup but there's no real way for it to function. In
order to connect everything together, we need to create a UI script.
UI Script
In the UI scene, select the UI node and create a new script called UI. Let's start with our
variables.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
First, we have the on_end_turn function. This gets called when a turn is over, so we're going to
reset the UI.
The we have the update_resource_text function which updates the two resource labels to
show the player's current resource values.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Now we need to connect the buttons. In the UI scene, do the following for the EndTurnButton,
MineButton, GreenhouseButton and SolarPanelButton...
So back in our script, we'll have 4 new functions. Let's start with the three building buttons.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Then we have the end turn button function.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Next, let's hop into the GameManager script and create the _ready function. Here, we're going
to initialize the UI.
At the end of the end_turn function, let's also update the UI.
Finally, at the bottom of the place_building function, we can update the resource text UI.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved
Conclusion
Congratulations on completing the tutorial!
You just created a 2D, turn-based strategy game in Godot. Through this journey, we've covered
a wide array of topics, from setting up objects that give and take resources, to creating a tile-
based map that provides visual clues about where buildings can be placed. Further, with turn-
based gameplay mechanics also introduced, we've tackled a key component for many other
sorts of strategy games as well!
From here, you can expand upon what you've learned to add more systems, work on existing
ones we touched on here, or even start a new strategy game project with Godot. Regardless,
thank you very much for following along with the tutorial, and we wish you the best of luck with
your future Godot games.
This book is brought to you by Zenva - Enroll in our Godot Game Development Mini-Degree to master 2D
and 3D game development with the free, open-source Godot game engine
© Zenva Pty Ltd 2020. All rights reserved