Godot 4.5 Beginner Tutorial: Build a Survivors-Like Roguelite (Part 1)
602 segments
Today we're going to start building the
foundation of one of the most addictive
genres in indie games, the survivor
rogue light. Now, welcome back to GDO
Dev Checkpoint. Today we're starting a
highly requested series, the survivor
style action rogike. It's addictive,
chaotic, and believe it or not, the
codebind is surprisingly approachable,
and by the end of this video, you'll
have a hero that moves smoothly in a
world that goes on forever. Let's get
building. First, let's get our scene set
up. Now, we're not going to use a
generic node 2D for our player. We're
going to need some physics. So, we're
going to use a character body 2D. This
node's going to handle some collisions
and movement logic for us automatically.
So, other node or search for a character
body 2D right in here. Going to create
that and rename this to player.
Now, in order to see our player, we're
going to need a sprite 2D. So, you right
click, add child node, sprite 2D. Now,
you can use whichever sprite you'd like,
but once again, I'm going to use some
Kenny's assets. Thousands, completely
free. Very generous site if you haven't
checked them out. I recommend it highly.
I'm going to use some pixel platformer
assets for tile maps. And I'm going to
use the creature mixer, which is on the
Hio. I'll link all these in the
description. If you use this tool, you
can get sprites automatically.
And here's our base guy. We're just
going to use him. In order to get this
sprite, you just click on this menu here
and then you save the sprite sheet
wherever you want to save it. And what
you end up with is a little sprite sheet
with four frames. And once you have
that, I'm going to right click on my
file system here and create a new folder
called sprites.
And with sprites highlighted, I'm going
to click and drag my new sprites into
the folder. Now that they're imported,
here they are. Here's our little guy.
Now I can click and drag. Let's see the
sprite 2D is selected. Click and drag my
creature sheet into my texture here.
And of course, we don't need all four
frames on here. And how do we change
that? Well, you go to animation in the
inspector with sprite 2D selected. And
we have horizontal frames and vertical
frames. One vertical frame, so one's
fine, but we have four horizontal
frames. So, I'm going to change this to
four. Now, we have our zero frame
animation right here. Let's fix this
blurry. Now you can do it individually
per sprite in the texture filter, but we
can do it projectwide too now with the
new GDO settings. So project
project settings. You want to search for
texture
filter.
There we are. Textures. So default
texture filter. We're going to change it
from linear to nearest. Now this is
going to keep your pixel art nice and
crisp. So once you close that, you see
how nice that looks. Now, now if you
don't want to do it projectwide, you can
still just do it on the sprite itself.
Just go to nearest, but we'll click
inherit because this inherits from the
project settings. And great. Now we want
our sprite to be standing on the yaxis
zero here. So we want to change our
offset to -12. There we go. And we get
him his feet sitting right there. Now we
also need a animation. So, we're going
to use our animation frames. So, you
right click the player. We're going to
add an animation player right there.
And with the animation player selected
down here, we're going to add a new
animation called idle.
And we only need one frame. So, we need
to worry about any of the settings for
now. We want to with our animation
player selected, select sprite 2D. And
then we're going to go down to our frame
here in our animation. We're just going
to use the zero frame. So we just do
that by selecting this key here. Create.
And now we have our zero frame
animation. And we can loop this. Even
though it's not really an animation yet,
but if you have a more difficult one,
then the loop will matter more as you'll
see in our run animation. So we play
that, it's just going to play the same
frame over and over. Now our idle setup.
Now with that, we need to set up our run
animation. New and call this run.
Then we want to add the frames per
second here. We're going to use eight
frames per second, so it's not too slow,
but we only have four frames to use. So
we in our by this little clock here,
animation length, we'll change that to
four. We can zoom in. If you hold
control and the mouse wheel or use this
little bar down here, you make sure we
have four frames. And once again, with
our sprite 2D selected, make sure we're
starting on frame zero. We're going to
add the zero frame. create. Add one,
two, and then three. Now we have all
four frames in there. Now here you want
to make sure this update mode is
discreet. It should be, but if it's not
for some reason, just make sure it is or
else it'll get all funky as just see. So
here's the discreet. If we play now, we
have a nice run animation. Oh, now we
need it to loop though. Loop. So play.
Nice run animation. If yours looks like
it's jittering at the end like this,
then you probably have continuous mode
on. See, continuous mode tries to keep
it continuous after this third frame. If
you look on our frame section here, it
tries to slowly go back to zero before
it gets to zero. And we don't want that.
So, we just want discreet so it uses our
frames appropriately.
Now, we have that set up. The last thing
we need is something that's going to
detect collisions. You'll see from this
node configuration warning, it says it
needs a collision shape 2D or a polygon
2D. We're going to use a collision shape
2D. Right click, add child, collision
shape 2D. And then this needs a shape.
We're just going to use a circle since
our enemies going to our player is going
to be dodging enemies. A circle feels
smoother than a box. So if we click in
this shape in the inspector here, circle
shape. Now, we want this circle shape
just to be on our feet. We don't want
our collision box too high. the player
will be super frustrated. So, we'll just
cover the feet there. I'll bring it up a
little bit. Now, that's where our
collision's going to be. Our main torso
and legs.
Going to pause that. And then with that
all set up, we have unsaved scene. So,
we need to save it. Neither do Ctrl S or
scene, save scene. Now, we're going to
not save it in the root folder. We're
going to create a new folder with a
right click, new folder, scenes. Oh,
lowercase GDO
preference. All right, player. Save.
Then we have our player saved in our
scenes folder. Now for the movement. In
platformers, we worry about gravity, but
in a top-own survivor game, we just need
X and Y movement. We're going to use a
specific function called input.get
vector. This is going to be crucial
because it prevents the player from
moving faster diagonally than they do in
a straight line, which is a common math
bug in beginner games. Now, the first
thing we want to do is actually set up
our own inputs. Now, in the project
project settings, in our input map here,
we're going to set up our own movement
actions. Now, GDO 4.5 does have built-in
actions here, which have the UI left,
right, up, and down, but you'll see it
does not actually include WD, which is
what most players prefer, at least
right-handed players. We're going to
keep the arrows and set those up in our
new ones, and the joyad and set those up
in our new ones as well. That'll make
ours more modular and customizable. So,
we'll hide these. We're going to move
our own here or use our own called move
left. And for this one, we want to add
an event. And for left, we're going to
use a. This is listens for your input.
Just push a. Okay. And then we also want
to use the arrow key left. So, add
another event left on the arrow key for
our left-handed people. And we can use
the joypad if you'd like, which is just
as easy. You click the event again and
click left on your joyad. Okay. And we
also want to have a move right. Move
right. And for this one, that event,
move right, which is D, and right on the
arrow key.
And then we want right on our joypad.
All right. We also need move up.
Not the underscore up. That's what we're
going to use. I'm use add event. Up is
W. Also up on the arrow key and also up
on the joyad.
Great. Last one. Move down. Move down.
There we go. Which is S and down on the
arrow and then down on the joyad.
Now we have a functional Whoops. Down on
the joypad. Now we have a functional
input map. customizable and one we could
use to our own without messing with the
built-in defaults. We'll close that. Now
that we have them, well, we need to use
them. So, we're gonna go to the player
here, attach a script, not in the scenes
folder, though. We want to put it in the
So, if you click on this path here, if
you don't know, you click there, go up
to our root, and we're going to create a
new folder. Right click, new folder
called scripts. Keep organized. You'll
thank yourself later. Player GD open
scripts. Keep the template for now.
There we go. I'll make this get rid of
this here. Make this bigger and zoom in
a little bit. Now you'll see the UI
accept UI left UI right uses by default
but we changed that because we have want
to use W. So actually we can get rid of
all this code in here. Just the boiler
plate code. We'll keep the physics
process. We are going to use that. And
we're also going to grow these constants
variables. We don't need these right
now. We are going to use an export
variable called speed. So the same just
an export same 300. Now why an export
instead of a constant? Well, we want
this adjustable in the inspector. So if
you controlclick export you can mark the
following property as exported editable
editable in the inspector doc just so we
can finagle with it if we want to
without having to come into the script.
All right. And you see it's it's
highlighted. It's cautioning. It's only
just saying that we're not using our
delta. If you click down here, we're not
using it. If we don't want to use it
right now, we can underscore here to get
rid of this caution, which I like. That
way, I know my cautions and my warnings
are valid. Now, inside our physics
process here, we're going to keep our
move and slide. We're going to enter
down and then tab over here, and we're
going to create a variable called
direction. This way we can track our
input get vector the function we're
talking about to get our direction. Now
you'll see once you come into this
parenthesis here after get vector should
come up with all of our actions we just
created. If it doesn't then you want to
check your input functions or check your
spelling here. So the first one we're
going to do move left. You can double
click here. That way we don't got to
worry about spelling it correctly. We're
just going to add all these in. Move
left, move right, move up, and then move
down.
There we go. Now, after we have our
direction, we're going to enter down
here. And then we're going to apply
velocity. Let's make some notes here so
we know what we're doing here later.
Apply velocity. And this top one here,
we're just going to get input direction.
So, left, right, up, down.
There we go. So, we're going to go into
this apply velocity. How do we do that?
Well, velocity is a keyword in GDAU
already. So, we can use that and use our
direction we just got. And then we're
going to multiply that by how fast we
want to go or speed. Now, after that, we
know how fast we're going. We just need
to know what animation to play while
we're moving. So, we're going to handle
animation
player here. So, we're going to check if
the velocity.x. So the left and right
does not equal to zero. So not equal to
zero means we're moving left and right.
But we also need to make sure we're not
moving up and down. So or the velocity.
So up and down, not velocity. Yeah,
wait. Velocity.
There you go. Doty does not equal zero.
So that means we're out standing still.
Up or down axis. So colon. Then we enter
down into there. And we're going to get
our animation player with this money
symbol. Now, once you do that, it should
pop up with these two here. If it
doesn't, then you perhaps change the
name on your animation player. So, you
want to make sure this actually I close
this down. We have our animation player.
It's named exactly like it is here. If
you changed it, you just have to make
sure this has matches. So, you can do is
actually click and drag this into your
code. If you drop it anywhere, it'll pop
up with the reference to it. Oops. So,
now that we know ours matches, we want
to play something. So, what do we want
to play when we're moving? We want to
play our run animation. So, play. And
once you come up with that, it should
pop up automatically with your
animations we set up earlier. We want to
run. So, the other thing we want to do
is if we're not running, not a comma, we
want to actually stop. So, we play our
idle animation. So once again, we'll
call our animation player play and idle.
Now we want to detect if we're going
left or right because we want our sprite
actually to face the direction we're
moving. So we want to handle the sprite
flipping. And we do that by checking if
our velocity x is greater than zero.
That means we're going to the right. So
positive x means we're going right. So
I'll show you where we're actually
accessing. I'll minimize this. In our
sprite 2D here in our offset, we're
accessing the flip H, so the horizontal.
If I go back to our 2D, you can see
we're actually facing right already. So,
if we want to go right, we want to keep
this false. Now, if we're going left, we
want to actually activate this to true.
Then, we turn to the left. So, we'll
keep it default. Fault to the right.
Now, back in our script, now we know
we're accessing. We want to go into this
function here and we want to access our
sprite 2D. And once again, money symbol
S should pop these up unless you changed
your sprite uh 2D name. They just want
to match this node here. So we are
sprite 2D default. So sprite 2D.flip
h. Now we're going right. So we want to
keep it false. Now l if the velocity x
is less than zero that means we're going
left. So once again our sprite 2D money
symbol there flip h is going to be true.
Now once you go back and forth left and
right should flip accordingly. Now last
thing and most important in these
physics processes in GDO is the move and
slide. Now this handles character
movement. So we're going to move the
character with the move and slide. you
don't have this, it's not going to work.
The movement slide actually has when it
handles the velocity, it handles the
delta inside the movement slide, which
is why we don't use it specifically. You
only use this if you want to access
frame specific stuff after the movement
slide. Then we go and save this script.
Now, if we go back into our 2D section
here, we're going to scroll out a little
bit and we see our viewport window here.
We want to access our player. Click a
player node and let's click this move
mode here. Move your player down into
the middle of the viewport area. And
while we're here, we are going to access
access the transform. Let's make our guy
a little bigger at five. That way we can
see what's happening. Now you've reached
a checkpoint. Go ahead and run the scene
by pressing F6 or use the current run
current scene button in the top right.
Looks like a film reel. Now move your
player to the right. Keep going. What
happens? Well, you walk off the screen
into the void. We need the game to
follow us. Now, I want you to try to
figure out which node we need to add to
fix this before I show you. Go ahead and
give that a try.
Now, the answer is the camera 2D node in
GDAU. If a camera is a child of a moving
object, it automatically is going to
track that object. So, let's lock the
view to the hero. Now, first off, let's
go ahead and reset our transform back to
zero. We want to keep our player at zero
and save that. And then we also probably
want to scale down our guy a little bit.
So we can go back to one. If we want to
scale our character up, we can do it
when we get into the main game scene. So
with our player selected, we right
click, add child node, camera 2D. So
right here, I'm going to create.
It really is that simple. So now we have
this purple box surrounding our
character. If we hide it, it goes away.
Then we see it again once we unhide it.
Now, you can do things like position
smoothing and add drag to make it a
little more fancy, especially with being
able to see. If we run this now, run
current scene. Now, we notice our
character starts right in the middle, no
matter which way we go, up, down, left,
or right. It's hard to tell because
we're in a gray void. So, actually, if
we close this, enable position
smoothing. We're going to turn this off
later, but for now, enable it. We're
current scene. And now we have this
where I can see the camera catching up
with us as we move. We also see that
jury movement. We don't want that
either. So in a top down survivor game,
we're just going to keep that position
smoothing off. We'll be able to see that
we're moving once we add a ground in our
main game. So with all that back set,
position smoothing off, no drag, camera
2D setup, our player is
ready. Go and save that. So right now
we're just walking on a gray void. We
need a ground. So in previous versions
of GDO, this required a complex setup
with background and layer nodes. But in
GDAU 4.5, we can use the new streamlined
parallax 2D node.
Back in our project here, we want to
actually scene new scene. This going to
be a 2D scene. Then we're have a node 2D
popup. We're going to rename that to
main game. Now, with this main game
selected, we're going to rightclick, add
child node. We're going to add something
called a parallax
2D right here. That'll create that.
Now, we want to set the repeat with
parallax 2D repeat. We're going to
select this to repeat about three or
four times. So, that's going to ensure
that it draws extra copies so it
prevents the flickering edges. And we
also want to scroll down to our ordering
here. Make sure it's always in the
background. So, we're just going to do
negative 100. That way, we know our
ground is always on the bottom. So, I
want now we need to add the ground. So,
our sprite I'm going to add from the
pixel platformer. I'm going to add some
ground that we have in here like this
one here. And you get that from the
Kenny assets. They're free to download
and you can use them in anything you'd
like. Creative common CCO. And with our
after you get that downloaded and pick
which one you want, sprites and make
sure that's selected. And what I'm going
to do in the pixel platform tile
section, I'm use tile 01 04. If you want
to use the same ones I'm using.
All right. Now, we just need to right
click on our parallax 2D, add a child
node, sprite 2D.
And our sprite 2D, I'm going to select
this ground I'm going to use. Click and
drag. Drop that in there. Now we have to
change this texture here and we need to
make sure repeat is enabled. If it's not
enabled, it will not work. So once
again, it's texture with the sprite 2D
enabled. Repeat. Okay. And to enable the
infinite loop here, click our parallax
2D. Find the repeat size here in the
inspector and find your tile size. If
you double click on it or you can hover
over it, the dimensions are 18 by 18 on
mine. Or you can double click and it
should say in the bottom right hand
section. So with our parallax 2D
selected, repeat size, we're going to
use
18 by 18. Now we know our repeat size
will match our sprite size. We also need
to make it a little bigger. As we run it
now, we'll be able to see the edges
here. So we go back to our sprite 2D.
What we want to do is change this region
here. So, select that to on. Now, it'll
disappear. But now, we change our width
and our height. This will give us our
ground that will fill our entire
viewport. So, we can't see when it's
being replicated. So, we're just going
to do something large like 4,000.
4,000 on both the width and the height.
There we go. If you zoom out, this block
here is all that will ever be rendered
for the ground, but infinitely. And
since we have the camera that
automatically tracks us, we don't need
to write any code. It just works.
So now we just need to get our player in
here. So with our main game selected so
it doesn't become a child of the
parallax. So select the main game,
select this chain link here, instantiate
child scene. We're instantiate our
player. So click on that. Now we have
our player in the scene. You also want
to make sure your player is below your
parallax 2D. Since we changed the Zorder
index, it should still draw on the
bottom. But as practice in 2D games,
GDAU draws from the bottom up. So the
higher it is in the hierarchy, the lower
it is in the Z order. Great. Now we have
our player in here. We can actually test
this. Now we're on the current scene.
Oh, we need to save our scene first. So,
in our scenes folder, main game, save it
as that. Click save. Our game should
start. And there we are. Now, we can run
left, right. So, our code is working for
our flipping sprite. And we can go as
far as we like. If you want to see this
in action, you can click this parallax
2D or no, we can click this remote
first. Sorry. Click this remote, expand
out the main game, then click the
parallax 2D. Now, if you go back into
our game here, now if you move around,
scroll down a little bit in the parallax
2D section, the screen offset. If we
move around, you can see the ground
parallax actually moving. So, we move to
the right, move to the left, move
diagonally. This ground is following us.
Now, the world is infinite. You can go
as far as you want. Fantastic start.
Now, we have a physics-based character,
normalized diagonal movement, a tracking
camera, and a world that never ends. You
built the engine that's going to drive
the game. Now, in the next video, things
are going to get dangerous. We're going
to build the horde. We'll script enemies
that spawn endless around the edges of
the screen and relentlessly chase the
player. Make sure your code is saved,
and I'll see you there. Now, if you
found this helpful at all or fun, leave
a comment what your GDO game dev goals
are. I love seeing your stuff. Now,
please like, subscribe, and hit that
notification bell. It really helps out
the channel. And thank you to all our
current and past Patreon and coffee
members. Your generous support keeps the
channel moving. Now, if you want early
access to tutorials, source code, or
suggesting future tutorials, please
consider becoming a member yourself. The
links are in the description. I'm
Spaghetti Syntax, and remember, finished
not perfect, fail fast, fail often.
Always stay curious, and I'll see you at
the next checkpoint.
Ask follow-up questions or revisit key timestamps.
This video explains how to build the foundation for a survivor roguelike game in GDevelop. It covers setting up the player character with a CharacterBody2D node, adding a sprite, configuring animations (idle and run), and implementing collision shapes. The tutorial also details how to set up custom input actions for movement (WASD and arrow keys), script the player's movement using `input.get_vector` for normalized diagonal movement, and handle sprite flipping to face the direction of movement. Additionally, it demonstrates how to add a Camera2D to make the game world follow the player and how to create an infinite scrolling ground using the Parallax2D node. The video concludes with a functional player character in an endless world, setting the stage for adding enemies in the next tutorial.
Videos recently processed by our community