As you know every game has a character and most 2D games have a main character who is generally a character you control for easy understanding. Today I will guide you to create Character Movement. This article consists of 2 parts as well as 2 types of character creation. Why are there 2 parts? Because it depends on your assets because most of them have 2 types of assets, 1 is the movement in each image and the other is the movement that is all in 1 image.
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
You need to study from lesson 0 to this lesson to understand all the instructions when Game programming with Godot Please.
And without further ado, let’s get started
Character Animation:
I will guide you to do type 1 first.
Start:
First: Delete Sprite old and created for myself AnimatedSprite
AnimatedSprite: A node that can use multiple textures to animate
Here I guide you to use my assets and if any of your assets are different from mine but it is of the same category as below, it can be applied. It has many separate photos
Please download it and put it in the game folder
Next we will create the character
You click on AnimatedSprite and change the name to Player then on the right of the Player there is a setting column in the Frames section to create a new Frame for you.
Then click on the newly created SpriteFramse will display a table (click like a tilemap).
Here you can see the word default on the left, delete it and create a new animation
Click like photo to create new Animations
Make yourself 4 of them Idle – Run – Jump – Fall
In Idle, please drag them all in the folder
Do the same with the other parts
And in the Jump section
Watch out for anim8 and anim11
Anim8 is jump and anim11 is fall why? Because 8 is when you jump up and 11 is when you land, you can do the same with other assets if you don’t understand, you can inbox me or go to Group Anonyviet Community to ask.
If your character is blurred like the image from Import back to 2D pixels
Please change them one by one in the FIlesystem section
After editing, our character will be sharp again
And we’re done with Character Creation Next is Coding
And you adjust the collection for yourself
Game character movement code
And I will guide you to coding for Character Motion. Your game character can move according to the keys you programmed.
No part script > character
Code for me to add the following part
Line: 12 – 13 – 16 – 17 – 20 – 24 -25 -26- 27 – 28
And below I will explain to you
$Player
: is that you call Node in the script using $ to call any Node in a Node
$Player.play()
: you run the Animation you did just now
$Player.flip_h
: is it helps you turn left, right if you try to remove these 2 lines and then run the game, move left + right, you will see something different than when you don’t remove these 2 lines
From line 24 > line 28 is the code that helps you to jump and still apply animations.
After running the game we will have a complete character:
In the next episode, I will guide you to create friction to control your speed, when you move, you will see it running fast, so there will be 1 more friction.