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

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

4 ways to fix bluetooth connectivity on Windows 11
Tips

4 ways to fix bluetooth connectivity on Windows 11

August 8, 2025
How to know the computer is tracked and processed by Keylogger
Tips

How to know the computer is tracked and processed by Keylogger

August 7, 2025
Opal: Create applications who do not need to write code
Tips

Opal: Create applications who do not need to write code

August 3, 2025
How to activate a new Start menu on Windows 11
Tips

How to activate a new Start menu on Windows 11

July 29, 2025
Intellgpt: AI tool for osint and data science
Tips

Intellgpt: AI tool for osint and data science

July 28, 2025
How to create Google Ai Pro 12 months free with Indian student account
Tips

How to create Google Ai Pro 12 months free with Indian student account

July 27, 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

Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
Wowhay.com – The door opens the world of modern knowledge and network culture

Wowhay.com – The door opens the world of modern knowledge and network culture

August 13, 2025
Instructions on how to fix Screen Time Limited Reached on RoBlox

Instructions on how to fix Screen Time Limited Reached on RoBlox

August 13, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
Wowhay.com – The door opens the world of modern knowledge and network culture

Wowhay.com – The door opens the world of modern knowledge and network culture

August 13, 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

Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 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í mm88 8XBET mm88 trang chủ new88

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í mm88 8XBET mm88 trang chủ new88

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