• 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

How to change the default font on Windows 10
Tips

How to change the default font on Windows 10

April 13, 2026
5 tips for using a Browser to replace an App (helps save RAM, time and money)
Tips

5 tips for using a Browser to replace an App (helps save RAM, time and money)

April 13, 2026
How to make funny MeMe photos without Photoshop within 10 seconds
Tips

How to make funny MeMe photos without Photoshop within 10 seconds

April 11, 2026
How to quickly design your own Logo without Photoshop
Tips

How to quickly design your own Logo without Photoshop

April 10, 2026
How to convert Website into App on Windows
Tips

How to convert Website into App on Windows

April 9, 2026
Instructions for getting 3 months of Adobe Express Pro for free
Tips

Instructions for getting 3 months of Adobe Express Pro for free

April 9, 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
Inline Feedbacks
View all comments

Recent News

Japanese Watch Week: Choose the color that suits your destiny, start the new year well at Mobile World

Japanese Watch Week: Choose the color that suits your destiny, start the new year well at Mobile World

April 20, 2026
4K Video Downloader Plus – Tool to download YouTube videos on macOS

4K Video Downloader Plus – Tool to download YouTube videos on macOS

April 20, 2026
How to add Watermark to Google Docs to protect copyright

How to add Watermark to Google Docs to protect copyright

April 19, 2026
How to intercept traffic using Burp Suite to analyze HTTP/HTTPS

How to intercept traffic using Burp Suite to analyze HTTP/HTTPS

April 18, 2026
Japanese Watch Week: Choose the color that suits your destiny, start the new year well at Mobile World

Japanese Watch Week: Choose the color that suits your destiny, start the new year well at Mobile World

April 20, 2026
4K Video Downloader Plus – Tool to download YouTube videos on macOS

4K Video Downloader Plus – Tool to download YouTube videos on macOS

April 20, 2026
How to add Watermark to Google Docs to protect copyright

How to add Watermark to Google Docs to protect copyright

April 19, 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

Japanese Watch Week: Choose the color that suits your destiny, start the new year well at Mobile World

Japanese Watch Week: Choose the color that suits your destiny, start the new year well at Mobile World

April 20, 2026
4K Video Downloader Plus – Tool to download YouTube videos on macOS

4K Video Downloader Plus – Tool to download YouTube videos on macOS

April 20, 2026
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

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