• 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 add sliders to Facebook Stories to easily rewind videos
Tips

How to add sliders to Facebook Stories to easily rewind videos

April 21, 2026
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
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

Tips to completely turn off CAPTCHA codes on iPhone and Mac are super simple

Tips to completely turn off CAPTCHA codes on iPhone and Mac are super simple

April 25, 2026
Compare Poco X8 Pro and Poco X7 Pro: A new step for the “king” of mid-range performance

Compare Poco X8 Pro and Poco X7 Pro: A new step for the “king” of mid-range performance

April 24, 2026
How to compress online videos for free without losing quality

How to compress online videos for free without losing quality

April 24, 2026
Top 5 apps to view good days 2026 for free on iOS and Android

Top 5 apps to view good days 2026 for free on iOS and Android

April 23, 2026
Tips to completely turn off CAPTCHA codes on iPhone and Mac are super simple

Tips to completely turn off CAPTCHA codes on iPhone and Mac are super simple

April 25, 2026
Compare Poco X8 Pro and Poco X7 Pro: A new step for the “king” of mid-range performance

Compare Poco X8 Pro and Poco X7 Pro: A new step for the “king” of mid-range performance

April 24, 2026
How to compress online videos for free without losing quality

How to compress online videos for free without losing quality

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

Tips to completely turn off CAPTCHA codes on iPhone and Mac are super simple

Tips to completely turn off CAPTCHA codes on iPhone and Mac are super simple

April 25, 2026
Compare Poco X8 Pro and Poco X7 Pro: A new step for the “king” of mid-range performance

Compare Poco X8 Pro and Poco X7 Pro: A new step for the “king” of mid-range performance

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