First you need to understand what an RPG is: English RPG is Role Playing Games, RPG is a game form where players will role-play the characters in the game for turn-based or real-time combat.
| Join the channel Telegram of the AnonyViet 👉 Link 👈 |
In this part we will create a character. Accompanied by a state machine with animation tree with Godot
Before that, please download the asset for yourself.
Here we will use Spritesheet.
Character
Sprite
First, we will put the character image into the Sprite as usual.
![[Godot RPG] #2: Character 30 [Godot RPG] #2: Character 29](https://anonyviet.com/wp-content/uploads/2020/08/1.png)
Notice the Attribute column (Inspector)
There will be VFrames and HFrames that those of you who have done with the previous tutorial will know.
- VFrames is the length of the Spritesheet
- Hframes is the verticality of the Spritesheet
Here:
- Hframes equal: 13
- Vframes equal: 16
![[Godot RPG] #2: Character 31 [Godot RPG] #2: Character 30](https://anonyviet.com/wp-content/uploads/2020/08/2-1.jpg)
After the set is complete, you will see
After setting 2, you will see the Player shrink as usual.
CollisionShape2d
Please set collisionshape as in the picture because this is a TopDown RPG game, not a game like the first Tutorial. This I will explain in a video on my channel, adjust like this because it will be more reasonable with titles. RPG game especially for objects in Godot.
![[Godot RPG] #2: Characters [Godot RPG] #2: Characters](https://anonyviet.com/wp-content/uploads/2020/08/3-1.jpg)
Animation Player
You create the Animation Player node
![[Godot RPG] #2: Character 33 [Godot RPG] #2: Character 32](https://anonyviet.com/wp-content/uploads/2020/08/4-1.jpg)
Then create a new Animation that will include:
- idle : stand still
- run : run
- attack : attack
- dead : dead
Then create a new Track for yourself in animation IDLE
![[Godot RPG] #2: Character 34 [Godot RPG] #2: Character 33](https://anonyviet.com/wp-content/uploads/2020/08/5-1.jpg)
Then select Sprite
![[Godot RPG] #2: Character 35 [Godot RPG] #2: Character 34](https://anonyviet.com/wp-content/uploads/2020/08/6-1.jpg)
Then select Frames
![[Godot RPG] #2: Character 36 [Godot RPG] #2: Character 35](https://anonyviet.com/wp-content/uploads/2020/08/7-2.jpg)
Then right-click and select Insert Key and then Insert so that it is equal to the number of Frames of Animation
![[Godot RPG] #2: Character 37 [Godot RPG] #2: Character 36](https://anonyviet.com/wp-content/uploads/2020/08/8-1.jpg)
Here I will leave the photo with the number of Frames. I don’t know about other Engines but it’s like this with Godot
![[Godot RPG] #2: Character 38 [Godot RPG] #2: Character 37](https://anonyviet.com/wp-content/uploads/2020/08/9-1.png)
Then I will Insert Key with the number of Frames
In IDLE it’s 12 so I’ll insert 12 keys
You can use the bottom bar to adjust the size
![[Godot RPG] #2: Character 39 [Godot RPG] #2: Character 38](https://anonyviet.com/wp-content/uploads/2020/08/10-2.jpg)
Use the one below to adjust the track time
![[Godot RPG] #2: Character 40 [Godot RPG] #2: Character 39](https://anonyviet.com/wp-content/uploads/2020/08/11-1.jpg)
So I have finished editing, you guys do the same for the other ones.
State Machine With Animation Tree
State Machine: means state machine, with state machine you can manage your actions more easily and State Machine is different from Finite Machine. In Godot, there is an AnimationTree node that makes it easier for us to implement State Machine
You guys add AnimationTree node for yourself
![[Godot RPG] #2: Character 41 [Godot RPG] #2: Character 40](https://anonyviet.com/wp-content/uploads/2020/08/12-1.jpg)
Where TreeRoot chooses Nodestatemachine
Where Assgin chooses ANimationPlayer
![[Godot RPG] #2: Character 42 [Godot RPG] #2: Character 41](https://anonyviet.com/wp-content/uploads/2020/08/14-2.jpg)
Then Right Click to add all the animation you just created
![[Godot RPG] #2: Character 43 [Godot RPG] #2: Character 42](https://anonyviet.com/wp-content/uploads/2020/08/15-4.jpg)
Here then
Pink: Connect (arrow helps signal transmission)
Green: Clear
Purple: When this is present, Animation will run first when starting
Cam: Animation Finally just run the animation with this = Stop
![[Godot RPG] #2: Character 44 [Godot RPG] #2: Character 43](https://anonyviet.com/wp-content/uploads/2020/08/16-2.jpg)
Here I will Connect IDLE with other animations
![[Godot RPG] #2: Character 45 [Godot RPG] #2: Character 44](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-15-43.png)
As the picture above, Idle will connect via attack ie IDLE can transmit data through attack but cannot transmit because attack has no plan to talk to idle
![[Godot RPG] #2: Character 46 [Godot RPG] #2: Character 45](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-15-54.png)
As shown in the picture above, the two sides are connected. So when we are in IDLE, press attack it will run attack and after the attack finishes it will run to idle.
Please connect with the rest. If there is a dead one, just connect from idle to it because when you die it returns idle what else :D?
![[Godot RPG] #2: Character 47 [Godot RPG] #2: Character 46](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-18-53.png)
I will set start to idle so that when starting up the player will be stationary, right? so when standing still it will run animation idle. But when you first run the game, the player is standing still and running animtion run or attack.
![[Godot RPG] #2: Character 48 [Godot RPG] #2: Character 47](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-19-09.png)
And assign END at dead. What do you do when you die :D.
That’s it, the animation tree is done, next is the code
CODE
Here, we will use a bit of object-oriented code.
create yourself an enum containing state machine (state machine) including IDLE,RUN,ATTACK,DEAD and 1 state variable will be equal to IDLE.
![[Godot RPG] #2: Character 49 [Godot RPG] #2: Character 48](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-39-14.png)
Then next we have to define each state when acting. Here I will use match (same as case/switch) and change the name laydau Nhapvao Fort Trangthai_move
![[Godot RPG] #2: Character 50 [Godot RPG] #2: Character 49](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-39-46.png)
Next I need to access AnimatinoTree to be able to run Animation and turn on the AnimationTree Then I will have the command:
![[Godot RPG] #2: Character 51 [Godot RPG] #2: Character 50](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-30-22.png)
Then next I have to check if Player is stationary then it will run animation idle if not stationary ie move will run moving animation and check when player moves right it will rotate right and when player moves left then it will turn left.
![]()
![[Godot RPG] #2: Character 53 [Godot RPG] #2: Character 52](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-41-09.png)
Next I will create a Camera for easy viewing.
![[Godot RPG] #2: Character 54 [Godot RPG] #2: Character 53](https://anonyviet.com/wp-content/uploads/2020/08/17-1.png)
Then when you move, you will see it rotate right and left to run the animation.
That’s it, see you in the next post






