• 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

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

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