• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

[Tạo 2D Platformer Game với Godot] Part 5: Character Design

AnonyViet by AnonyViet
January 27, 2023
in Tips
0

In this section, I will show you how to combine animations in movement to create a complete character as well as show you how to make the character jump.

Join the channel Telegram of the AnonyViet 👉 Link 👈

Create Folder

[Tạo 2D Platformer Game với Godot]  Part 5: Character Design

In the previous section, I forgot to guide you to create more Folders to be able to manage files neatly and cleanly. So you create yourself 2 new Folders in Scenes, Map and Player.

Map: Used to store the levels of the game.

Player: Used to contain Scenes related to Player.

F5

Oh, and I forgot to tell you that when you press F5 you will run the default scene and press F6 and you will run the selected scene.[Tạo 2D Platformer Game với Godot]  Part 5: Character Design 7

You can change it in Project -> Project Settings

Animation

[Tạo 2D Platformer Game với Godot]  Part 5: Character Design 8

In part 3, I showed you how to create Animation for characters and now I will show you how to apply it.

Code

onready var animation= $AnimatedSprite

To use Animations, you must have access to the AnimatedSprite node..

There are two ways to access it:

  • Create a border and assign an AnimatedSprite node to it, when assigning a node to a variable you need to add onready before var.
  • You can call it directly using the ” $ ” symbol (eg $AnimatedSprite.position) or using get_node() ( eg get_node(“AnimatedSprite”).position)
extends KinematicBody2D

var tocdo = 200
var trongluc = 7000
var chuyendong = Vector2()
var huong_dichuyen
onready var animation = $AnimatedSprite

func _physics_process(delta):
    chuyendong.y = trongluc * delta
    huong_dichuyen = Input.get_axis("ui_left","ui_right")
    
    if huong_dichuyen != 0:
        chuyendong.x = lerp(chuyendong.x,huong_dichuyen * tocdo,0.5)
        animation.play("chay")
        scale.x = scale.y * huong_dichuyen
    else:
        chuyendong.x = lerp(chuyendong.x,0,0.1)
        animation.play("dungyen")

        
    chuyendong.normalized()
    move_and_slide(chuyendong,Vector2.UP)

So, I will add a few lines in the above code to make the character move with animation.

Here I will explain:

Current animation.play() :

  • That I will call the animation variable that the animation variable I have assigned is the AnimatedSprite node so I can access it and after accessing it I will use the function play() of the AnimatedSprite node to run the animation. The animation name is the name of the animation you created in the AnimateSprite node.

Current scale.x :

  • This is the line that will allow you to rotate the character left and right.
  • scale.y ( is 1) * Huong_dichuyen (left press is -1 right is 1 so if left press = -1 then scale.y is 1 * with Huong_dichuyen is -1 it will output -1).
  • scale.x if it is -1, it will rotate left, but if it is equal to 1, it will rotate right. You can test in Transform -> Scale of any node.
  • And I put it in the first if function so that when the character moves it rotates, otherwise it won’t rotate.
extends KinematicBody2D

var tocdo = 200
var trongluc = 10
var chuyendong = Vector2()
var huong_dichuyen
onready var animation = $AnimatedSprite

func _physics_process(delta):
    
    

    huong_dichuyen = Input.get_axis("ui_left","ui_right")
    if huong_dichuyen != 0:
        chuyendong.x = lerp(chuyendong.x,huong_dichuyen * tocdo,0.5)
        animation.play("chay")
        scale.x = scale.y * huong_dichuyen
    else:
        chuyendong.x = lerp(chuyendong.x,0,0.1)
        animation.play("dungyen")

    
    if is_on_floor():
        if Input.is_action_just_pressed("ui_accept") :
            chuyendong.y = -250
    else:
        animation.play("nhay")

    chuyendong.y += trongluc 
    chuyendong.normalized()
    chuyendong = move_and_slide(chuyendong,Vector2.UP)

Above is the code that I have edited and optimized it.

Current if is_on_floor() :

  • That I will check that the character it is standing on the floor.
  • If I stand on the floor and I press the button Way then switchong.y = -250 ie the character will move up 1 bit and then the machine will read the code from above and see the line moving.y += in luc then it will move down again.

Still line else: :

  • Is the opposite of is_on_floor() when I have jumped on it ie no longer on the floor, I will run the jumping animation.

[Tạo 2D Platformer Game với Godot]  Part 5: Character Design 9

In the running animation, I found it to be quite slow and inconsistent, so go in and adjust the speed from 5 fps to 10 fps.

[Tạo 2D Platformer Game với Godot] Part 5: Character Design

This is the final result.

summary

That’s it, in this part I have guided you to make the character jump and apply animation to the movement.

The article achieved: 5/5 – (100 votes)

Tags: characterDesignGameGodotPartPlatformertạovới
Previous Post

How to turn off WifiVinaphone on Internet Modem

Next Post

How to share WiFi password on Android and iPhone securely?

AnonyViet

AnonyViet

Related Posts

Windows 7/8.1/10 users will be upgraded to Windows 11 for free
Tips

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving ChatGPT Plus for 1 month for free in 2026
Tips

Instructions for receiving ChatGPT Plus for 1 month for free in 2026

July 28, 2026
Some reasons I don’t like Windows 11
Tips

Some reasons I don’t like Windows 11

July 27, 2026
Instructions on how to get free Facebook white ticks
Tips

Instructions on how to get free Facebook white ticks

July 27, 2026
Collection of Windows 11 wallpapers for computers and phones
Tips

Collection of Windows 11 wallpapers for computers and phones

July 26, 2026
Don’t install leaked Windows 11
Tips

Don’t install leaked Windows 11

July 25, 2026
Next Post
How to share WiFi password on Android and iPhone securely?

How to share WiFi password on Android and iPhone securely?

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted

Recent News

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving the free Certified LLM Security Expert certificate

Instructions for receiving the free Certified LLM Security Expert certificate

July 30, 2026
MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

July 29, 2026
What is quantum resistant cryptography? Why must the Internet change?

What is quantum resistant cryptography? Why must the Internet change?

July 29, 2026
Windows 7/8.1/10 users will be upgraded to Windows 11 for free

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving the free Certified LLM Security Expert certificate

Instructions for receiving the free Certified LLM Security Expert certificate

July 30, 2026
MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

July 29, 2026
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving the free Certified LLM Security Expert certificate

Instructions for receiving the free Certified LLM Security Expert certificate

July 30, 2026
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply