• 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

[Lập trình Game] Lesson 1: Create movement for the character

AnonyViet by AnonyViet
February 1, 2025
in Tips
0

Okay, and welcome to the series Game programming with Godot Engine 3.2 And today I will guide you to move up, down, left and right for my first character.

Join the channel Telegram belong to Anonyviet 👉 Link 👈

Create character

First we open the software. Please pay attention to the section scene

scene

This is where you will do your node. View Post What is node?

Here you can choose Other Node Or 2D Sense All. This article I choose Other Node

When created, it will appear below, and I change my name World:

[Lập trình Game]  Lesson 1: Create movement for the character

Next, press the mark + Or press the combination Ctrl + A To create new nodes under the world

And you find Kinematicbody2d for yourself:

[Lập trình Game]  Lesson 1: Create movement for the character

Then stay Kinematicbody2d select Collsetshape2d and Sprite okay

Kinematicbody2d

And here after creating you have 1 character moving Basic can be anything (the main character, the enemy, ..)

Kinematicbody2d: Means dynamic body (used to create objects as 1 character)

Sprite: Used to create photos for your character

Collsetshape2d: The collision shape (used to determine the collision with another object)

Part Sprite You click and drag icon.png Or any image you want to make a character, dragging into the texture.

pull icon.png

And here it has appeared:

[Lập trình Game]  Lesson 1: Create movement for the character

Next click Collsetshape 2D and in Inspector select Shape> New Rectangles2d

[Lập trình Game]  Lesson 1: Create movement for the character

At the character's face interface, you Pull the dot in the blue line and the red dot in the purple line so that it is equal to the sprite.

[Lập trình Game]  Lesson 1: Create movement for the character

Code for character moving

So already Done the character creation Next is the code.

Click on Kinematicbody2d And choose for yourself as a photo to create a script:

Create script

Script: The place where you will code and code will apply to run your game and character

Attach Node Script

  • Language: Language used for programming
  • Path: Path to save
  • Load: Create script

And press Load.

After clicking Load, the code interface will appear, ban Delete all content from line 4 to line 17

Code interface

Declare variables

Get yourself a variable declaration code as follows:

[Lập trình Game]  Lesson 1: Create movement for the character

Anyone who programmed then knows how to declare the variable ^^ Basically and whoever does not know, I explain the following:

Var: Declare a variable to use it. Example: Var Tocdodichuyen, Var Ketqua, Var huongdichuyen

So Var Chuyendong = Vector2 () in which Vector2 () is?

Vector2 (): A variable used for mathematics in 2D and in mathematics, you know the coordinate axis x, y, …

Here:

  • x = horizontal motion
  • y = straight motion
  • FUNC _PHYSICS_PRocess is a physical process that means the movement of kinematicbody2d
  • FUNC _READY is the process of ready: When you declare a variable in Ready it will be loaded when downloading the game

And in Physics_process, you also declare a variable as above, but when it moves it, it will be loaded

Pass: yes it is okay

Motion code

Code for me the following paragraph. This is the code Right motion, left

Motion code

In here I will explain the paragraph IF statement okay. Whoever learned programming, the IF statement is not difficult

if input.is_ACTION_Prisheded (“UI_RIGHT”): is: When you press the right arrow key, it will move to the right and vice versa Elif is left and Else: It will stand still after moving.

Move_and_slide (move and surf): Help your character move

Press F5 or F6 To try it out.

F5: Run the default scene

F6: Running Scene is editing. Example: worldnumberone is the default scene and worldnumbervietnam Is scene being edited. When pressing F5 even in scene worldnumbervietnam Then it will run Worldnumeberone If pressed F6 it will run worldnumbervietnam without running Worldnumeberone )

If it is like this, you can adjust it:

Error

Click as photos:

[Lập trình Game]  Lesson 1: Create movement for the character

We are as photos:

Lock moving

When you press this it will help you Fix the ingredients inside it.

And if you press the lock, it will Node lock Again on the screen can not be transferred and cannot press

Then we pull it out between:

[Lập trình Game] Lesson 1: Create movement for the character

If this is like this, press the right arrow and the left to see it moves:

See left and right motion

If you want Move up, down then the code is as follows:

[Lập trình Game]  Lesson 1: Create movement for the character

And I have instructed you to program a basic character, then the next article will be about: Friction force after running, gravity, jump, ground.

Goodbye and see you again in the following article.

Deathgm!

Previous Post

How to use LMSTUDIO to install AI offline on PC running Deepseek, Sonet …

Next Post

How to use chatgpt O3 for free

AnonyViet

AnonyViet

Related Posts

7 Gmail utilities you should install to increase work efficiency
Tips

7 Gmail utilities you should install to increase work efficiency

November 18, 2025
Instructions for checking the security of Google Chrome using Safety Check
Tips

Instructions for checking the security of Google Chrome using Safety Check

November 17, 2025
Instructions on how to edit Facebook scheduled posts
Tips

Instructions on how to edit Facebook scheduled posts

November 16, 2025
Suggested AI command to create a rustic and charming image of a Ban Lien girl
Tips

Suggested AI command to create a rustic and charming image of a Ban Lien girl

November 16, 2025
Windows 10 will have a new, simpler interface
Tips

Windows 10 will have a new, simpler interface

November 16, 2025
How to check what data Facebook is controlling about you
Tips

How to check what data Facebook is controlling about you

November 15, 2025
Next Post
How to use chatgpt O3 for free

How to use chatgpt O3 for free

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Tempi – Professional website design platform opens the way for Vietnamese businesses to breakthrough in the digital age

Tempi – Professional website design platform opens the way for Vietnamese businesses to breakthrough in the digital age

November 18, 2025
Instructions for installing RustDesk on Windows 11, replacing TeamViewer

Instructions for installing RustDesk on Windows 11, replacing TeamViewer

November 18, 2025
7 Gmail utilities you should install to increase work efficiency

7 Gmail utilities you should install to increase work efficiency

November 18, 2025
How to update vehicle data on iHanoi to synchronize information

How to update vehicle data on iHanoi to synchronize information

November 17, 2025
Tempi – Professional website design platform opens the way for Vietnamese businesses to breakthrough in the digital age

Tempi – Professional website design platform opens the way for Vietnamese businesses to breakthrough in the digital age

November 18, 2025
Instructions for installing RustDesk on Windows 11, replacing TeamViewer

Instructions for installing RustDesk on Windows 11, replacing TeamViewer

November 18, 2025
7 Gmail utilities you should install to increase work efficiency

7 Gmail utilities you should install to increase work efficiency

November 18, 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

Tempi – Professional website design platform opens the way for Vietnamese businesses to breakthrough in the digital age

Tempi – Professional website design platform opens the way for Vietnamese businesses to breakthrough in the digital age

November 18, 2025
Instructions for installing RustDesk on Windows 11, replacing TeamViewer

Instructions for installing RustDesk on Windows 11, replacing TeamViewer

November 18, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

trang chủ shbet trang chủ f168 trang chủ qq88 nhà cái 78win

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

trang chủ shbet trang chủ f168 trang chủ qq88 nhà cái 78win

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