How To Make a Topdown RPG in Godot 4: Adding The Player (Part 1)

DuoTutor / DoisTutor
18 May 202317:14

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

00:00

๐ŸŽฎ 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.

05:28

๐Ÿƒโ€โ™‚๏ธ 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.

10:29

โš”๏ธ 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.

15:55

๐Ÿ›ก๏ธ 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

In the context of the video, 'Project Settings' refers to the configuration options available in a game development engine, such as Godot, where developers can adjust various parameters to customize the behavior and appearance of the game. The video mentions adjusting 'default texture filter' under 'Project Settings' to 'nearest' to ensure pixel art maintains high quality without becoming blurred or low resolution.

๐Ÿ’กPixel Art

'Pixel Art' is a form of digital art where images are created on the pixel level, often used in video games for characters, backgrounds, and other elements. The video emphasizes the importance of setting the texture filter to 'nearest' to preserve the crispness and quality of pixel art in the RPG series being developed.

๐Ÿ’กWorld

In game development, 'World' often refers to the game environment or the space where the game takes place. The video instructs on creating a 'world' by naming a new scene 'to world' and dragging in an icon to serve as a reference model, which is crucial for ensuring that the player's movements are accurately represented within the game world.

๐Ÿ’กCharacter Body

A 'Character Body' in the video refers to a type of physics body used in Godot for character entities. The video describes creating a character body with a collision shape to handle interactions with the game world. This is a fundamental aspect of game development, as it determines how the character moves and interacts within the game environment.

๐Ÿ’กAnimation Player

The 'Animation Player' is a node in Godot used to play and control animations. The video details adding an 'Animation Player' node to the character to handle various animations such as idle, run, and attack. This is essential for bringing the character to life and providing visual feedback to the player's actions.

๐Ÿ’กAnimation Tree

An 'Animation Tree' in Godot is a node that allows for complex animation logic, such as blending between different animations. The video explains setting up an 'Animation Tree' to manage the transitions between different character states like idle, run, and attack animations, which is crucial for smooth and responsive character movement in the game.

๐Ÿ’กSprite

A 'Sprite' in game development is a two-dimensional image or animation that is integrated into a scene. The video describes dragging art files into a 'Sprite' node to display the character's animations. This is a key step in visually representing the character within the game world.

๐Ÿ’กPhysics Process

In the video, 'Physics Process' refers to a method in Godot for updating the game state based on physics calculations. It is used to process player inputs more effectively. The video suggests changing a script's process mode to 'Physics Process' to improve the responsiveness of the game's input handling.

๐Ÿ’กMove and Slide

'Move and Slide' is a method in Godot for moving characters or objects while considering collisions. The video explains initiating a 'Move and Slide' function to control the character's movement. This function is essential for ensuring that the character moves smoothly and interacts correctly with the game's environment and obstacles.

๐Ÿ’กBlend Space 2D

A 'Blend Space 2D' in Godot is used for creating smooth transitions between animations based on input variables. The video describes setting up a 'Blend Space 2D' for attack animations, allowing the character to have different attack positions and movements. This contributes to the fluidity and realism of the character's actions within the game.

๐Ÿ’กCollision Shape

A 'Collision Shape' in game development defines the area that can interact with other objects in the game world. The video mentions adding a 'Collision Shape' for the sword hitbox to detect collisions during attack animations. This is important for creating realistic interactions and ensuring that attacks have an effect within the game.

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

play00:00

foreign

play00:04

for

play00:05

RPG series we're going to implement the

play00:09

player

play00:10

let's get started

play00:12

so the first thing we're going to want

play00:14

to do before we do anything in this game

play00:16

is go to project project settings and

play00:19

then under textures under default

play00:21

texture filter we'll want to select the

play00:24

nearest setting

play00:26

that way all pixel art will become high

play00:29

quality and will not become low

play00:30

resolution what we're going to want to

play00:32

do next is create our world we'll do so

play00:35

by making a note to the

play00:38

just name it to world

play00:41

and we'll also want to drag in an icon

play00:45

so we have a reference model to make

play00:47

sure that our player is moving

play00:50

save the scene as world

play00:55

then run the scene in order to select

play00:57

the current

play01:00

now we're going to actually make the

play01:02

player and to do so we'll want to create

play01:04

a character body to the instead of a

play01:06

kinematic body

play01:08

we'll add a collision shape

play01:11

animation player

play01:15

animation tree

play01:17

it will also add a Sprite

play01:23

what I'm going to do next is create a

play01:25

new folder for a player

play01:28

it will also create a new folder for art

play01:33

and down here I will put the art files

play01:36

for our player

play01:41

next we'll want to drag the art from our

play01:45

folder here into the Sprite

play01:49

and as you can see we have all the

play01:52

animations here

play01:53

what we want to do is set our frames

play01:57

currently this one has 58 frames

play02:01

and then we will go under animation tree

play02:04

and select our animation player

play02:07

we'll want to remove our ready function

play02:10

because we will not be using it

play02:12

and we will want to create some on-ready

play02:16

variables

play02:18

good L4 uses at on readyvar and add

play02:22

export for any type of variable that is

play02:26

specified as such

play02:29

foreign

play02:49

to quickly interject the reason why I'm

play02:52

specifying the variable types is for

play02:56

performance so if you have a lower end

play02:58

computer this will greatly improve your

play03:01

performance for your program

play03:06

as the computer does not have to guess

play03:08

what type of variable it is

play03:11

all you have to do is do the semicolon

play03:13

followed by the type and then equals to

play03:19

next what we're going to want to do is

play03:21

change this to a physics process

play03:26

that way we can process

play03:28

the inputs much better than just the

play03:30

normal process

play03:40

this is a simplified version of getting

play03:44

inputs from

play03:46

the player but you can also do an array

play03:51

or use the vector function in order to

play03:55

get the inputs from the player

play04:10

next we'll want to create

play04:14

a specification for our velocity

play04:17

variable

play04:19

we'll simply just use the input vector

play04:22

and multiply it by your speed

play04:26

the next upcoming part is going to be

play04:28

important to understand if you want to

play04:30

add more animations though I will add

play04:33

new animations such as attack animations

play04:36

as well

play04:38

but you're going to want to make sure

play04:41

that if you have an animation that

play04:44

doesn't even particularly move the

play04:47

player you'll want to be sure that all

play04:50

the blend positions which I will explain

play04:52

in future part of the video

play04:55

uh are being done when the vector is uh

play04:59

not at zero

play05:28

finally our most important part of this

play05:30

is to initiate our move and slide

play05:33

function

play05:39

these arrows oh

play05:42

make sure to indent properly

play05:46

you will get errors if you try to run

play05:47

this code but we will add our animations

play05:51

next

play05:54

this next part will just be initializing

play05:57

and setting our animations

play06:14

all right

play06:18

we are now going to go over to our

play06:20

animation player

play06:22

and what we'll do here is create a new

play06:27

blunt space 2D and we'll call this idle

play06:32

it works slightly different compared to

play06:34

goodo

play06:36

uh be sure to make sure that this is set

play06:39

to enabled instead of Auto otherwise

play06:42

your character will glitch and these

play06:44

animations will not work

play06:46

we'll also do run here

play06:51

and then set our animations

play06:54

for idle and run

play06:55

to transition back and forth to each

play06:58

other

play06:59

but we'll go under Advanced and click

play07:03

our mode to set to enabled

play07:07

we will not connect to end yet but we

play07:10

may in future videos

play07:13

here you want to click the corners that

play07:17

are specified of what the animation is

play07:21

going to go to

play07:23

this next part generally confuses people

play07:26

so I would advise to pay attention

play07:29

uh the up part here

play07:32

will do uh idle up

play07:36

because if it is uh going up it means

play07:39

the character is looking away

play07:41

but if we're going down

play07:44

then that means the character is looking

play07:45

at you

play07:50

and then the left and right are still

play07:53

the same

play07:59

and we'll apply the same thing to our

play08:01

run animation

play08:11

next we're going to go over to our

play08:12

Collision shape and just create a circle

play08:17

be sure it's a circle

play08:19

as that way if we add y sorting in the

play08:23

future your character can go around

play08:25

objects and also appear as if they can

play08:28

hide behind or in front of them

play08:32

so we'll save go to our world and then

play08:35

we'll instant our

play08:38

uh player here

play08:42

almost forgot to mention though was we

play08:45

need to add a camera

play08:47

and be sure to have the zoom close I put

play08:51

it at half

play08:53

just to make sure that we can see our

play08:56

character

play08:58

and for our smoothing options we'll do

play09:01

enabled for both it will set each option

play09:04

speed to 4.

play09:07

before we start testing our game though

play09:09

we'll also want to add

play09:12

our inputs

play09:17

and it's a little bit different in Godot

play09:19

so you just type uh the character here

play09:22

but you also have a list of the

play09:25

characters that you can implement

play09:29

set your animation tree to active before

play09:32

you start playing as well now that we're

play09:35

in the game you can see that our player

play09:37

moves and it has a slight drag in its

play09:40

camera which is good because it makes it

play09:43

uh smooth better

play09:45

and you can see with a reference here

play09:47

that our character is moving

play09:49

thank you for watching all files will be

play09:52

available in the GitHub down below and

play09:55

I'll see you guys in the next video

play09:57

now we're going to set our attack

play09:59

animations

play10:02

now what we'll want to do to set up is

play10:04

uh add a marker to the which looks like

play10:09

this

play10:11

and then we'll add an area to the

play10:15

and then we'll add a collision shape

play10:18

rename this to sword hitbox

play10:22

and make sure that you select a shape

play10:26

that corresponds well with your attack

play10:28

animation

play10:29

in this case we'll be using a

play10:33

capsule here

play10:38

now the reasoning behind using a marker

play10:40

2D is to make sure that we have a way to

play10:44

rotate our

play10:45

Sword hitbox without having to manually

play10:48

change it

play11:21

sword uh hitboxes Collision shape and

play11:25

you want to select the disabled option

play11:29

for the beginning animation

play11:31

but the moment that the

play11:34

attack animation happens

play11:37

you have the animation enable the

play11:41

Collision box

play11:44

then down here we will disable it once

play11:48

the animation is over

play11:51

next if your attack animation is at a

play11:54

different position what you'll want to

play11:56

do is go under transform of the marker

play12:00

to the

play12:01

and click on rotation and select your

play12:05

rotation here

play12:09

this will allow you to add different

play12:12

positions for your attack box without

play12:15

needing to change anything

play12:37

next we will go to our animation tree

play12:40

and we will add a new blend space 2D

play12:43

this one will be called attack

play12:50

one I should say because in future

play12:52

videos we will be adding combos in

play12:55

different attack patterns

play12:58

and as such as previously mentioned you

play13:01

will just add the different positions of

play13:04

our attack animations

play13:13

thank you

play13:18

next we will then connect our animations

play13:23

now the way we'll do this is by

play13:26

connecting to both the idle and also our

play13:29

run

play13:31

back and forth

play13:33

reasoning being is if our player is

play13:35

running but they want to attack they're

play13:38

also able to do that otherwise you will

play13:41

not be able to attack unless you are

play13:44

completely idle

play13:48

before we Implement anything into our

play13:49

code we'll also want to add a bun for

play13:53

attack

play13:55

and we will press F or any button that

play13:58

you would like to use for attack and

play14:00

then we'll close

play14:01

next we'll go back to our code

play14:03

and then we will Implement in our

play14:07

animation tree a set function for

play14:10

parameters

play14:12

Attack One be sure to implement the one

play14:17

and then blend position

play14:27

next we will add a Boolean

play14:30

which is is attacking

play14:33

which is equal to false

play14:35

and we will set this

play14:38

uh Boolean to check if is attacking

play14:44

is equal to false

play14:48

reasoning being is that way our player

play14:50

cannot move while we attack

play15:54

now we will go back and we will

play15:56

implement the final part of the code

play15:58

which is the attack part

play16:02

so we will do if input that is action

play16:07

just pressed

play16:09

attack

play16:13

set attacking equal to true

play16:21

and then we will do the animation

play16:39

before we test be sure this is Attack

play16:41

One and also

play16:44

our move and slide function is under

play16:47

uh the Boolean here

play16:51

now that we booted up we can walk around

play16:54

but when we move and then we attack we

play16:57

can no longer move and we are in an

play16:59

attack animation

play17:02

thank you for watching I hope you

play17:04

enjoyed this video and this helps with

play17:07

any making any games in good o4 and I'll

play17:11

see you guys in the next YouTube series

Rate This
โ˜…
โ˜…
โ˜…
โ˜…
โ˜…

5.0 / 5 (0 votes)

Related Tags
Godot TutorialRPG DevelopmentPixel ArtCharacter AnimationGame DesignCoding BasicsAnimation TreePlayer MovementAttack MechanicsGame Optimization