• 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

[Top Down Game với Godot] #1: Move

AnonyViet by AnonyViet
February 1, 2023
in Tips
0

Introduce

Hi guys, welcome to the next series on game programming with Godot Engine. Today I will guide you to program the Top Down game with Godot. In this article, I will guide you to move the character for the top down game.

Join the channel Telegram of the AnonyViet 👉 Link 👈

With the Top Down game, we don’t need gravity like the first series but just need to move in 4 directions. Usually if you search youtube for articles about basic top down game, you will see that people often use the if command to check Input and Moving, doing that takes a lot of time, so I’ll do one quickly :3.

Note: This will be song 1 for both seires

Create Project

Then as usual we will create a new project.

[Lập Trình Top Down Game]  #1: Move Top Down 19

Project Name: Project Name

Project Path: Path

Renderer:

Choose OpenGL 3.0 if you want to make PC & Android games – Choose OpenGL 2.0 if you want to make web games.

After you have the link, click Create Folder and then click Create & Edit to get started

Create Sense

Like the previous posts with Godot we will create a new Sense that will contain characters and other things

[Lập Trình Top Down Game]  #1: Move Top Down 20

You can use either a Black Node or a 2D Node. I will use 2D Node and name it World then you press Ctrl + S to save it. I will save it in the folder containing Scenes (Sence).

[Lập Trình Top Down Game]  #1: Move Top Down 21

Character Creation

You click the + sign next to the name of the Sense to create a new sence

[Lập Trình Top Down Game]  #1: Move Top Down 22

Then click Other Node or + Under the word Sense to add Node. You guys find yourself Node KinematicBody2D. This is a “Kinematic Body” button that makes it easier for us to move and perform.

Then you guys add 2 Nodes as “Sprite” and “CollisionShape2D“.

Sprite: Is the image node for the parent node in short, the node that displays the image for the KinematicBody2D

CollisionShape2D: is the node representing the collision data in 2D space, ie the shapes used to collide. Anyone who has been in contact will understand.

Generally in Godot it is: KinematicBody2D is the soul – Sprite is the outer appearance – CollisionShape2D is the skeleton

[Lập Trình Top Down Game]  #1: Move Top Down 23

I will rename the KinematicBody2D to Player for easy identification.

With Sprite, I don’t have an asset yet, so let’s temporarily use the icon.png available in godot’s filesystem :v next post I’ll find the asset.

You click on the Sprite and then click on the Icon, then drag over the Sprite’s Texture

[Lập Trình Top Down Game]  #1: Move Top Down 24

Next we will set CollisionShape2D for it. Click on the collision node and then in the shape you choose a shape for it, it’s up to you here, I choose the square for it to be square with the Sprite

[Lập Trình Top Down Game]  #1: Move Top Down 25[Lập Trình Top Down Game]  #1: Move Top Down 26

So we have created the basic character of the basic :’).

Then you can save it

Next will be the Script section, click on the paper with the blue + sign to create the script, remember to click on the Player node to create it, don’t create it in Sprite or CollisionShape2D.

[Lập Trình Top Down Game]  #1: Move Top Down 27

Move Code

We will use GDScript by Godot. This is Godot’s own language based on Python and Lua.

As mentioned at the beginning of the article, I will guide you to advanced moves :3.

Create Function Take Input Data

We will create a new function called laydau_nhapvao(): ie the function will take all input from the outside. For example, if you press the K key, it will attack, that is to get information from the external input.

So I will create a func function laydau_nhapvao():

In it, I will create a variable that is vector_dauvao assigned = Vector2.ZERO or Vector2() (2 pieces = each other).

vector_dauvao is the variable used to define Vector2(x,y) ie the beginning of x,y. If left pressed, it will move left(Vectoc(-1,0)), and if pressed right will move right(Vector2(1,0)), up then (Vector2(0,-1) not is Vector2(0,1) as in math, in game vice versa).

func laydau_nhapvao():
var vector_dauvao = Vector2.ZERO
vector_dauvao.x = Input.get_action_strength("ui_right")- Input.get_action_strength("ui_left")
vector_dauvao.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")

move_and_collide(vector_dauvao)

Here:

vector_dauvao.x = Input.get_action_strength(“ui_right”) – Input.get_action_strength(“ui_left”): ie Input(input).get_action_strength(“ui_right”) (getting action strength can be understood as taking input as input). when right is pressed) then subtract Input.get_action_strength(“ui_left”) => ui_right(Vector(1,0)) and ui_left(Vector(-1,0)) when right pressing without left pressing the action of pressing that’s right Vector2 = Vector2(1,0) and since left side = 0 so 1-0 will = 1 (then when we move to the right Vector(1,0) the x it = 1 then we don’t move to the left so it = 0 when we move to the left it’s new = -1 so 1-0 will = 1 and = 1 then it moves to the right and to the left the opposite, vector_dauvao.y does the same)

Apply migration

Then I will add a command to apply movement to the character that is move_and_collide (moving and collision is different from move_and-slide (moving and gliding) it also has the function of pushing other objects :)) that’s right can push other objects if it is move_and_slide it only moves and glides but cannot be pushed otherwise. If you use Rigdbody2D, both slide and collide can push it :3 a nice feature of Godot )

Call the function to get data

Then we have to call it to the physical process function (physical_process(delta)) or process (_process(delta)) you can see the basics here: Godot GDScript

[Lập Trình Top Down Game]  #1: Move Top Down 28

Instance Node

Then go to the sense world and instance node player to test

[Lập Trình Top Down Game]  #1: Move Top Down 29

Remember to drag the Player to the middle.

[Lập Trình Top Down Game]  #1: Move the Top Down 30

Then you press F5 or F6 to run the game (F5 selects the sence to run, F6 runs the sence you are working on) when running the game you press the arrow button to move. But you notice when moving horizontally with diagonal movement, the speed of cross movement is faster, not even like the other 2 moves, so we have 1 command to normalize it’s speed. .normalized().

So we’ll type

 vector_dauvao = vector_dauvao.normalized()

[Lập Trình Top Down Game]  #1: Move Top Down 31

Speed ​​and Delta

I will use the export var variable to output to the Inspector panel (this is a pretty OK feature of Godot)

VD:

[Lập Trình Top Down Game]  #1: Move Top Down 32

First we declare

export var speed = 100 so you can adjust as much as you like

Then we will * it in with vector_dauvao variable and * with delta always

You can do it like this.

[Lập Trình Top Down Game]  #1: Move Top Down 33

But for me, I created a new variable containing the above 3 for easy understanding.

[Lập Trình Top Down Game]  #1: Move Top Down 34

In laydau_nhapvao there is no delta so I will create 1 delta right on func laydau_nhapvao():

Then in_physical_process(deta): I just need to call it in.

Finish

So I finished lesson 1 in the series of game programming with Godot, then see you in the next post ;3

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

Tags: GameGodotMoveTopvới
Previous Post

M-Crypter v1.0.3 – Tool to help bypass Antivirus

Next Post

Download MorphVOX Pro 4.4.80 Full – Voice changer software

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
Download MorphVOX Pro 4.4.80 Full – Voice changer software

Download MorphVOX Pro 4.4.80 Full - Voice changer software

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