• 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 moves for the character

AnonyViet by AnonyViet
February 3, 2023
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, right for my first character.

Join the channel Telegram belong to AnonyViet 👉 Link 👈

Character creation

First we open the software. You pay attention in Section scene

scene

This is where you will implement your Node. View Posts What are Nodes??

Here you can choose Other Node Or 2D sense all okay. This article I choose Other Node

Once created, it will appear below, and I renamed it World:

[Lập trình Game]  LESSON 1: Create moves for the character 12

Next, press the sign + or press the combination Ctrl + A to create a new Node under World

And you find KinematicBody2D for myself:

[Lập trình Game]  LESSON 1: Create moves for the character 13

Then stay KinematicBody2D select CollsionShape2D and Sprite Please

KinematicBody2D

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

KinematicBody2D: Means Kinetic Body (used to create object like a character)

Sprites: Use to create your character’s photo

CollsionShape2D: Collision shape (used to determine where to collide with another object)

In the sprite you click and drag icon.png or any other image you want to use as a character, drag into the texture.

drag icon.png

And here it appeared:

[Lập trình Game]  LESSON 1: Create moves for the character 14

Next click on CollsionShape 2D and stay Inspector select Shape > New RectangleShape2D

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

At the character’s face interface, you drag the dot on the blue line and the red dot on the purple line so that it is equal to the sprite.

[Lập trình Game]  LESSON 1: Create moves for the character 16

Code for the character to move

So that’s it Finished character creation Next is Code.

You click KinematicBody2D and choose for yourself as the image to create the script:

create scripts

Script: Where you will code and that code will apply to run the game and your character

attach node script

  • Language: The language used for programming
  • Path: Path to save
  • Load: Create scripts

And press Load.

After clicking Load, the interface of the Code writing page will appear delete all content from line 4 to line 17

code interface

Declare variable

Type yourself a code that declares a variable as follows:

[Lập trình Game]  LESSON 1: Create moves for the character 17

Anyone who has programmed, knows how to declare a variable. ^^ It’s basic and for those who don’t know, I’ll explain as follows:

var: declare a variable to use it. VD: var tocdodichuyen, var ketqua, var huongdichuyen

So what is var conversion = Vector2() where Vector2() is ?

Vector2(): is a variable used for math in 2D and in math, you know the x, y coordinate axes, …

in here:

  • x = horizontal movement
  • y= straight motion
  • func _physics_process is a physical process i.e. kinematicbody2D
  • func _ready is process ready: when you declare a variable in ready it will be preloaded when the game loads

In physics_process, you also declare a variable as above, but it is loaded when it moves

pass: yes or no

Motion code

Code for me the following part. Here is the code right and left movement

motion code

Here I will explain the passage if . statement Please. Who has learned programming, the if statement is no longer difficult

if input.is_action_pressed(“ui_right”): is: when you press right arrow key it will move right And vice versa with elif is to the left and else: is that it will stay still after moving.

move_and_slide (move and glide): make your character move

Press F5 or F6 for a test run.

F5: run default scene

F6: run the scene being edited. VD: worldnumberone is the default scene and worldnumbervietnam is the scene being edited. When pressing F5 even in the scene worldnumbervietnam then it will run worldnumeberone if press F6 it will run worldnumbervietnam without running worldnumeberone )

If it is like this, you can edit it:

run error

Click as picture:

[Lập trình Game]  LESSON 1: Create moves for the character 18

We get as picture:

move lock

When you press this it will help you fix the components inside it.

And if you press the lock it will node lock back on the screen can’t move nor can’t press

Then we drag it to the middle:

[Lập trình Game] LESSON 1: Create moves for the character

Okay like this, you press the right and left arrows to see it move:

watch left-right movement

If you want up and down movement then the code is as follows:

[Lập trình Game]  LESSON 1: Create a move for the character 20

And I have instructed you to program a basic character, then the next lesson will be about: Friction force after running, Gravity, Jumping, Ground.

Goodbye and see you in the next post.

DeathGM!

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

Tags: charactercreateGamelậpLessonmovestrình
Previous Post

License Key Visual Studio 2019 (Professional/Enterprise)

Next Post

Share license key Visual Studio Enterprise 2019

AnonyViet

AnonyViet

Related Posts

How to write Shell Script in Linux/Unix
Tips

How to write Shell Script in Linux/Unix

December 6, 2025
How to completely uninstall WSL on Windows 11?
Tips

How to completely uninstall WSL on Windows 11?

December 6, 2025
Kinh nghiệm mua Laptop cho sinh viên nhóm ngành kế toán, kinh tế, xã hội…
Tips

Kinh nghiệm mua Laptop cho sinh viên nhóm ngành kế toán, kinh tế, xã hội…

December 5, 2025
8 tips for more successful PowerPoint presentations
Tips

8 tips for more successful PowerPoint presentations

December 4, 2025
Chrome extensions to improve productivity in 2021
Tips

Chrome extensions to improve productivity in 2021

December 2, 2025
How to create photos that run KPIs while crying using Gemini for the 12 zodiac animals
Tips

How to create photos that run KPIs while crying using Gemini for the 12 zodiac animals

December 1, 2025
Next Post
Share license key Visual Studio Enterprise 2019

Share license key Visual Studio Enterprise 2019

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

How to transfer music from other services to Apple Music, no app required

How to transfer music from other services to Apple Music, no app required

December 8, 2025
How to create Mind Map and Flowchart using ChatGPT is super simple

How to create Mind Map and Flowchart using ChatGPT is super simple

December 7, 2025
Free Gemini Google certification exam guide and Answers

Free Gemini Google certification exam guide and Answers

December 6, 2025
How to write Shell Script in Linux/Unix

How to write Shell Script in Linux/Unix

December 6, 2025
How to transfer music from other services to Apple Music, no app required

How to transfer music from other services to Apple Music, no app required

December 8, 2025
How to create Mind Map and Flowchart using ChatGPT is super simple

How to create Mind Map and Flowchart using ChatGPT is super simple

December 7, 2025
Free Gemini Google certification exam guide and Answers

Free Gemini Google certification exam guide and Answers

December 6, 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

How to transfer music from other services to Apple Music, no app required

How to transfer music from other services to Apple Music, no app required

December 8, 2025
How to create Mind Map and Flowchart using ChatGPT is super simple

How to create Mind Map and Flowchart using ChatGPT is super simple

December 7, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

trang chủ f168 nhà cái 78win https://www.qq8827.com/

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

trang chủ f168 nhà cái 78win https://www.qq8827.com/

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