• 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 10

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

Top 5 game programming languages ​​to learn now
Tips

Top 5 game programming languages ​​to learn now

June 8, 2025
[Godot Shooter] #2: Creating characters & shooting bullets
Tips

[Godot Shooter] #2: Creating characters & shooting bullets

June 7, 2025
What do you need to learn game programming? Is it difficult? How long does it take?
Tips

What do you need to learn game programming? Is it difficult? How long does it take?

June 6, 2025
Instructions for registering chatgpt team at $ 1
Tips

Instructions for registering chatgpt team at $ 1

June 5, 2025
How to engrave the right mouse menu error on Windows
Tips

How to engrave the right mouse menu error on Windows

June 5, 2025
How to create online meme photos is very easy with a few steps
Tips

How to create online meme photos is very easy with a few steps

June 5, 2025
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

Top 5 game programming languages ​​to learn now

Top 5 game programming languages ​​to learn now

June 8, 2025
The iPhone list is updated with iOS 26

The iPhone list is updated with iOS 26

June 8, 2025
Discover the glowing effect next to the iPhone ios 18 screen

Discover the glowing effect next to the iPhone ios 18 screen

June 8, 2025
[Godot Shooter] #2: Creating characters & shooting bullets

[Godot Shooter] #2: Creating characters & shooting bullets

June 7, 2025
Top 5 game programming languages ​​to learn now

Top 5 game programming languages ​​to learn now

June 8, 2025
The iPhone list is updated with iOS 26

The iPhone list is updated with iOS 26

June 8, 2025
Discover the glowing effect next to the iPhone ios 18 screen

Discover the glowing effect next to the iPhone ios 18 screen

June 8, 2025
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

Top 5 game programming languages ​​to learn now

Top 5 game programming languages ​​to learn now

June 8, 2025
The iPhone list is updated with iOS 26

The iPhone list is updated with iOS 26

June 8, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET https://kubet88.yoga/ bj88

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

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí SHBET https://kubet88.yoga/ bj88

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