How To Make a Topdown RPG in Godot 4: Adding The Player (Part 1)
Summary
TLDRThis tutorial video script guides viewers through creating a pixel art RPG character in Godot. It covers setting up project settings for pixel art quality, creating a world scene, and building a player character with a sprite and animations. The script details adding a collision shape, animation player, and implementing movement and attack animations. It also explains setting up an animation tree, handling inputs for player movement and attacks, and adjusting camera settings for a smooth gameplay experience. The video promises to provide all necessary files on GitHub and hints at future tutorials on advanced animations and game mechanics.
Takeaways
- 🎮 Start by setting the texture filter to 'Nearest' in project settings to maintain high-quality pixel art in the RPG series.
- 🌍 Create a 'World' node and set an icon for reference to ensure the player's movement is tracked correctly.
- 👤 Add a 'CharacterBody' with a collision shape, animation player, animation tree, and a Sprite to construct the player character.
- 📁 Organize assets by creating folders for the player and art, then drag the art into the Sprite node.
- 🔁 Set up the animation frames and configure the AnimationTree to manage different character states and transitions.
- 💻 Use 'on_ready' variables with explicit types for better performance, especially on lower-end computers.
- 🕹️ Implement a physics process for handling player inputs to improve responsiveness.
- 🏃 Create a velocity specification using the input vector multiplied by speed for character movement.
- 🎭 Add attack animations and ensure blend positions are set correctly when the movement vector is not at zero.
- 📸 Set up a 'Move and Slide' function to handle character movement and incorporate animations.
- 🔍 Configure the AnimationPlayer to enable smooth transitions between idle and run animations with proper settings.
- 🛡️ Create a circular CollisionShape for the player to facilitate interactions with the game world and potential future occlusion effects.
- 📸 Add a camera with zoom and smoothing settings to enhance the in-game viewing experience.
- 🔧 Set up inputs and activate the AnimationTree before testing the game to ensure character movements and animations work as intended.
- ⚔️ Implement attack animations with a marker and area to define the attack range and connect them to the AnimationTree for seamless transitions.
- 🛠️ Code the attack functionality to disable player movement during the attack and manage the attack animation state.
Q & A
What is the first setting adjustment recommended for a pixel art RPG series in Godot?
-The first setting adjustment is to go to Project Settings and under Textures, Default Texture Filter, select the 'Nearest' setting to ensure high-quality pixel art without low resolution.
How do you create a new world in the game?
-To create a new world, you make a new scene, name it 'World', and drag in an icon to serve as a reference model to ensure that the player is moving.
What are the essential components to add to the player character in Godot?
-The essential components to add to the player character include a CharacterBody, CollisionShape, AnimationPlayer, AnimationTree, and a Sprite.
Why is it important to specify variable types in Godot when creating a game?
-Specifying variable types in Godot is important for performance, especially on lower-end computers, as it allows the computer to know the type of variable without guessing, thus improving the program's performance.
How do you handle player inputs in the Godot game engine?
-Player inputs are handled by changing the script's process mode to 'physics process' which allows for better input processing compared to the normal 'process' mode.
What is the purpose of using a blend space 2D for animations in Godot?
-A blend space 2D is used for animations to smoothly transition between different animation states, such as idle and run, and to handle various directions and attack animations.
Why is it necessary to disable the 'Ready' function in the AnimationTree?
-The 'Ready' function is disabled in the AnimationTree because it is not used in this setup, and removing it simplifies the process and potentially improves performance.
How do you ensure that the player character's attack animation is synchronized with a hitbox?
-The attack animation is synchronized with a hitbox by enabling the hitbox's CollisionShape during the attack animation and disabling it once the animation is over.
What is the significance of using a Marker2D for the sword hitbox in the attack animation?
-A Marker2D is used for the sword hitbox to allow for easy rotation and positioning of the hitbox without manually changing the sword's CollisionShape during different attack animations.
How do you implement camera smoothing in Godot for a better player experience?
-Camera smoothing is implemented by adding a camera to the scene, setting the zoom level, and enabling smoothing options with a specified speed to ensure a smooth follow of the player character.
What is the role of the 'is attacking' Boolean variable in controlling the player's movement during an attack?
-The 'is attacking' Boolean variable is used to prevent the player from moving while attacking, ensuring that the attack animation plays without interruption from movement inputs.
Outlines
🎮 Setting Up Pixel Art in RPG Game Development
The video script begins with instructions for setting up a pixel art RPG game in Godot. The first step is to adjust the texture filter settings to 'nearest' for high-quality pixel art rendering. Next, the world is created by adding a note and an icon to serve as a reference model. The player character is then constructed with a character body, collision shape, animation player, animation tree, and a Sprite. Art files for the player are organized into folders and imported into the Sprite. The animation frames are set, and the AnimationTree is configured to remove the 'ready' function and create 'on_ready' variables for performance optimization. The script then transitions into setting up a physics process for better input handling and defining a velocity variable based on input vector and speed.
🏃♂️ Implementing Player Movement and Animations
This section of the script focuses on the implementation of player movement and animations. The move and slide function is initiated, and animations are added. The script explains how to set up the AnimationPlayer with 'idle' and 'run' animations, ensuring they transition smoothly. Advanced settings are adjusted to enable animations and define directional movement. A collision shape is created, and the script emphasizes using a circle shape for future y-sorting. The player is instantiated in the world with a camera set for a close-up view and smooth movement. Inputs are configured in Godot, and the script concludes with a demonstration of the player's movement and camera following in the game environment.
⚔️ Adding Attack Animations and Hitboxes
The script moves on to adding attack animations and configuring hitboxes for the player character. A marker 2D and area 2D are used to rotate and position the sword hitbox without manual adjustments. The hitbox's collision shape is enabled during the attack animation and disabled afterward. The script details how to set different positions for the attack box using the marker's rotation. An 'attack' blend space 2D is created in the AnimationTree, connecting it to both 'idle' and 'run' animations to allow attacks from different states. The script concludes with adding an attack input and setting up the corresponding animation and code logic.
🛡️ Finalizing Attack Mechanics and Testing
The final part of the script involves implementing the attack mechanics in the code. It includes setting the 'attacking' Boolean to prevent movement during attacks. The script explains how to connect the attack animation to both 'idle' and 'run' states, ensuring the player can attack from either state. The code is tested, and the player's ability to move and attack is demonstrated. The video concludes with a thank you message and a note that all files will be available on GitHub, with a teaser for the next video in the series.
Mindmap
Keywords
💡Project Settings
💡Pixel Art
💡World
💡Character Body
💡Animation Player
💡Animation Tree
💡Sprite
💡Physics Process
💡Move and Slide
💡Blend Space 2D
💡Collision Shape
Highlights
Start by adjusting the texture filter to 'nearest' in project settings for better pixel art quality.
Create a world scene and save it to begin setting up the game environment.
Add a character body with a collision shape, animation player, and sprite to create the player.
Organize assets by creating separate folders for player and art files.
Drag art assets into the sprite component and set up the animation frames.
Specify variable types for performance optimization, particularly on lower-end systems.
Switch to a physics process for better input handling and game performance.
Use the input vector multiplied by speed to define the player's velocity.
Set up the move and slide function to handle player movement within the game.
Create and enable idle and run animations using a blend space 2D in the animation player.
Add a camera with close zoom and enable smoothing for a better player experience.
Set up attack animations with a sword hitbox and rotate the hitbox using a marker 2D.
Enable and disable the collision shape during the attack animation for accurate hit detection.
Connect attack animations to both idle and run states, allowing the player to attack while moving.
Implement an 'isAttacking' boolean to prevent movement during the attack animation.
Transcripts
foreign
for
RPG series we're going to implement the
player
let's get started
so the first thing we're going to want
to do before we do anything in this game
is go to project project settings and
then under textures under default
texture filter we'll want to select the
nearest setting
that way all pixel art will become high
quality and will not become low
resolution what we're going to want to
do next is create our world we'll do so
by making a note to the
just name it to world
and we'll also want to drag in an icon
so we have a reference model to make
sure that our player is moving
save the scene as world
then run the scene in order to select
the current
now we're going to actually make the
player and to do so we'll want to create
a character body to the instead of a
kinematic body
we'll add a collision shape
animation player
animation tree
it will also add a Sprite
what I'm going to do next is create a
new folder for a player
it will also create a new folder for art
and down here I will put the art files
for our player
next we'll want to drag the art from our
folder here into the Sprite
and as you can see we have all the
animations here
what we want to do is set our frames
currently this one has 58 frames
and then we will go under animation tree
and select our animation player
we'll want to remove our ready function
because we will not be using it
and we will want to create some on-ready
variables
good L4 uses at on readyvar and add
export for any type of variable that is
specified as such
foreign
to quickly interject the reason why I'm
specifying the variable types is for
performance so if you have a lower end
computer this will greatly improve your
performance for your program
as the computer does not have to guess
what type of variable it is
all you have to do is do the semicolon
followed by the type and then equals to
next what we're going to want to do is
change this to a physics process
that way we can process
the inputs much better than just the
normal process
this is a simplified version of getting
inputs from
the player but you can also do an array
or use the vector function in order to
get the inputs from the player
next we'll want to create
a specification for our velocity
variable
we'll simply just use the input vector
and multiply it by your speed
the next upcoming part is going to be
important to understand if you want to
add more animations though I will add
new animations such as attack animations
as well
but you're going to want to make sure
that if you have an animation that
doesn't even particularly move the
player you'll want to be sure that all
the blend positions which I will explain
in future part of the video
uh are being done when the vector is uh
not at zero
finally our most important part of this
is to initiate our move and slide
function
these arrows oh
make sure to indent properly
you will get errors if you try to run
this code but we will add our animations
next
this next part will just be initializing
and setting our animations
all right
we are now going to go over to our
animation player
and what we'll do here is create a new
blunt space 2D and we'll call this idle
it works slightly different compared to
goodo
uh be sure to make sure that this is set
to enabled instead of Auto otherwise
your character will glitch and these
animations will not work
we'll also do run here
and then set our animations
for idle and run
to transition back and forth to each
other
but we'll go under Advanced and click
our mode to set to enabled
we will not connect to end yet but we
may in future videos
here you want to click the corners that
are specified of what the animation is
going to go to
this next part generally confuses people
so I would advise to pay attention
uh the up part here
will do uh idle up
because if it is uh going up it means
the character is looking away
but if we're going down
then that means the character is looking
at you
and then the left and right are still
the same
and we'll apply the same thing to our
run animation
next we're going to go over to our
Collision shape and just create a circle
be sure it's a circle
as that way if we add y sorting in the
future your character can go around
objects and also appear as if they can
hide behind or in front of them
so we'll save go to our world and then
we'll instant our
uh player here
almost forgot to mention though was we
need to add a camera
and be sure to have the zoom close I put
it at half
just to make sure that we can see our
character
and for our smoothing options we'll do
enabled for both it will set each option
speed to 4.
before we start testing our game though
we'll also want to add
our inputs
and it's a little bit different in Godot
so you just type uh the character here
but you also have a list of the
characters that you can implement
set your animation tree to active before
you start playing as well now that we're
in the game you can see that our player
moves and it has a slight drag in its
camera which is good because it makes it
uh smooth better
and you can see with a reference here
that our character is moving
thank you for watching all files will be
available in the GitHub down below and
I'll see you guys in the next video
now we're going to set our attack
animations
now what we'll want to do to set up is
uh add a marker to the which looks like
this
and then we'll add an area to the
and then we'll add a collision shape
rename this to sword hitbox
and make sure that you select a shape
that corresponds well with your attack
animation
in this case we'll be using a
capsule here
now the reasoning behind using a marker
2D is to make sure that we have a way to
rotate our
Sword hitbox without having to manually
change it
sword uh hitboxes Collision shape and
you want to select the disabled option
for the beginning animation
but the moment that the
attack animation happens
you have the animation enable the
Collision box
then down here we will disable it once
the animation is over
next if your attack animation is at a
different position what you'll want to
do is go under transform of the marker
to the
and click on rotation and select your
rotation here
this will allow you to add different
positions for your attack box without
needing to change anything
next we will go to our animation tree
and we will add a new blend space 2D
this one will be called attack
one I should say because in future
videos we will be adding combos in
different attack patterns
and as such as previously mentioned you
will just add the different positions of
our attack animations
thank you
next we will then connect our animations
now the way we'll do this is by
connecting to both the idle and also our
run
back and forth
reasoning being is if our player is
running but they want to attack they're
also able to do that otherwise you will
not be able to attack unless you are
completely idle
before we Implement anything into our
code we'll also want to add a bun for
attack
and we will press F or any button that
you would like to use for attack and
then we'll close
next we'll go back to our code
and then we will Implement in our
animation tree a set function for
parameters
Attack One be sure to implement the one
and then blend position
next we will add a Boolean
which is is attacking
which is equal to false
and we will set this
uh Boolean to check if is attacking
is equal to false
reasoning being is that way our player
cannot move while we attack
now we will go back and we will
implement the final part of the code
which is the attack part
so we will do if input that is action
just pressed
attack
set attacking equal to true
and then we will do the animation
before we test be sure this is Attack
One and also
our move and slide function is under
uh the Boolean here
now that we booted up we can walk around
but when we move and then we attack we
can no longer move and we are in an
attack animation
thank you for watching I hope you
enjoyed this video and this helps with
any making any games in good o4 and I'll
see you guys in the next YouTube series
Weitere ähnliche Videos ansehen
How To Make a Topdown RPG in Godot 4: Adding Combo Attacks and an Enemy(Part 2)
Start Your Game Creation Journey Today! (Godot beginner tutorial)
FlipaClip – INTERPOLATION in ANIMATION (tutorial)
How To Make a Topdown RPG in Godot 4: Adding Classes and Projectiles (Part 5)
How to make a Roblox JOJO game #1 | Making Stand Summoning
Collision Detection - How to Make a 2D Game in Java #6
5.0 / 5 (0 votes)