First you need to understand what RPG is: RPG English is the Role Playing Games, RPG is the type of game that the player will play the role of the character in the game to fight in turn or in real time.
| Join the channel Telegram belong to Anonyviet 👉 Link 👈 |
In this section we will create characters. Accompanied by State Machine with Animation Tree with Godot
Before that, please download the Asset for me.
Here we will use Spritesheet.
Figure
Sprite
First, we will remove the image of the character into Sprite as usual.
![[Godot RPG] #2: Characters 30 [Godot RPG] #2: Character 29](https://anonyviet.com/wp-content/uploads/2020/08/1.png)
Notice the Inspector column (Inspector)
There will be VFrames and HFrame who have done with tutorial first.
- Vframes is the length of spritesheet
- HFrames is vertical of spritesheet
Here:
- Hframes equals: 13
- Vframes equals: 16
![[Godot RPG] #2: Character 31 [Godot RPG] #2: Characters 30](https://anonyviet.com/wp-content/uploads/2020/08/2-1.jpg)
After the set is finished, you will see
After you finish the 2 sets, you will see the small player as usual.
Collisionshape2d
You set Collisionshape as a picture because this is the Topdown RPG game, not the first type of game like tutorial.
![[Godot RPG] #2: Character [Godot RPG] #2: Character](https://anonyviet.com/wp-content/uploads/2020/08/3-1.jpg)
Animation Player
You create node animation player
![[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 will include:
- IDLE: Stand still
- Run: run
- Attack: attack
- Dead: Dead
Then next to create a new track for me 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: Characters 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: Characters 35](https://anonyviet.com/wp-content/uploads/2020/08/7-2.jpg)
Then right -click to select Insert Key and then Insert so that it is equal to the frames number 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 let the image have the frames. I don’t know what other engines, but Godot is like this
![[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 equal to frames numbers
In idle, it is 12 so I will insert 12 key
You can use the bottom bar to adjust the small level
![[Godot RPG] #2: Character 39 [Godot RPG] #2: Character 38](https://anonyviet.com/wp-content/uploads/2020/08/10-2.jpg)
Use the bottom to adjust the track time
![[Godot RPG] #2: Characters 40 [Godot RPG] #2: Character 39](https://anonyviet.com/wp-content/uploads/2020/08/11-1.jpg)
So I finished adjusting, you do the same.
State Machine with Animation Tree
State Machine: Means a state -owned machine, with State Machine you can manage your actions easier and the State Machine is different from Finite Machine. At Godot, there is node as animationtree that makes it easier to perform State Machine
You add node animationtree for me
![[Godot RPG] #2: Character 41 [Godot RPG] #2: Characters 40](https://anonyviet.com/wp-content/uploads/2020/08/12-1.jpg)
In the place, Treeroot selects Nodestatemachine
At the Assginplayer
![[Godot RPG] #2: Characters 42 [Godot RPG] #2: Character 41](https://anonyviet.com/wp-content/uploads/2020/08/14-2.jpg)
Then right -clicked all the newly created animations
![[Godot RPG] #2: Character 43 [Godot RPG] #2: Characters 42](https://anonyviet.com/wp-content/uploads/2020/08/15-4.jpg)
Here then
Pink: Connect (arrow helps signal transmission)
Green: delete
Purple: When there is this, the Animation will run first at the beginning
Orange: Animation last just need to run animation with this = stop
![[Godot RPG] #2: Characters 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: Characters 45 [Godot RPG] #2: Characters 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, IDLE can transmit data via Attack but it cannot be transmitted because Attack does not have the plan to tell idle.
![[Godot RPG] #2: Characters 46 [Godot RPG] #2: Characters 45](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-15-54.png)
As the picture above, the two sides were connected to each other. So when we are in Idle, click attack it will run Attack and after the Attack ends it will run back to idle.
Please connect with the rest. There is a dead, only connect from Idle to only because when you die and then return IDLE to do: D?
![[Godot RPG] #2: Character 47 [Godot RPG] #2: Characters 46](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-18-53.png)
I will assign a start in Idle so that when you boot, the player will stand still, right? So when standing still it will run Animation Idle. But when you first ran the game that the player was standing still and running the Animtion Run or Attack.
![[Godot RPG] #2: Characters 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. When dying, what else do you run: D.
So it has finished the Animation Tree is the code
Code
Here, we will use an object -oriented code.
Create yourself the enum containing State machine (Status neck) Including IDLE, RUN, Attack, Dead and 1 status will be equal to IDLE.
![[Godot RPG] #2: Character 49 [Godot RPG] #2: Characters 48](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-39-14.png)
Then next we must determine each state when acting. Here I will use match (like case/switch) and change the name laydau nhapvao wall 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 Animationtree Then I will have a statement:
![[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 the player is standing still, it will run Animation Idle if not standing still means moving, it will run the animation moving and check when the player moves to the right it will rotate the right and when the player move left, it will turn to the left.
![[Godot RPG] #2: Characters 52 [Godot RPG] #2: Character 51](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-41-20.png)
![[Godot RPG] #2: Characters 53 [Godot RPG] #2: Characters 52](https://anonyviet.com/wp-content/uploads/2020/08/08-08-2020-02-41-09.png)
Next, I will create a camera to easily see.
![[Godot RPG] #2: Characters 54 [Godot RPG] #2: Characters 53](https://anonyviet.com/wp-content/uploads/2020/08/17-1.png)
Then when you move, you will see it turning left and right to run animation.
So you’re done appointments to the next lesson








