• 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 2: Gravity, moving and jumping surface

AnonyViet by AnonyViet
January 29, 2025
in Tips
0

Next, with the game programming series with Godot today I will guide you the next article is gravity, moving surface and dancing.

Join the channel Telegram belong to Anonyviet 👉 Link 👈

Oh, before doing, if you want to reopen the Sentce, you are working on the filesystem section and double -click on the previous sense you saved before and yours saved here. World.TSCN

World.TSCN

Move surface: The moving surface is the part that we let the character we move on it can say it is like the road surface for us to go.

To create the surface you do like you and this is just the basic of basic, if you want to create a moving surface like other games, people call it tilemap and tileset I will guide in the following article:

Create node Staticbody2d under the world

Create New Node 1

Staticbody2d

LIVE Staticbody I will change my name to Floor (double click on the name) and I also change the name Kinematicbody wall Player okay.

And like staying Node Player I will create 2 node To be Sprite: Pictures for Floor and Collset

Collset Here, the explanation is very difficult, so I explain briefly for those who understand it. Example:

When you create a sprite without Collset Then it is just an image, an image painted. If you create 1 Sprite + Collset Then it means that you use your hand to squeeze a bag of the ball into the wall, it will collapse. Collset And when you have collset, it is like inside the ball bag with a brick, when you press the ball, there is a brick you cannot squeeze it because the brick is hard. The general speaking is Sprite is a skin set still Collset is bone In that skin set.

Or can understand Collset is the frame To prevent the inner part for Sprite to operate

Here Staticbody2d Used for physical movement if you want to build a trap, a bridge, something standing still or moving as an obstacle, then use it Staticbody2d.

Then you do the same Lesson 1 With node player like this:

Node Player

I will not instruct specifically, but you have to remember each post to go up.

In Floor, click Sprite to notice the right part below canvasitem, then click in Visiable> Select modulate And adjust the color into any color.

quickly

Here I change to black

Mau Den

And as the picture on the boards can see that Sprite has changed to threatn but that Collset It presses again Sprite Then you change the position Collset up Sprite or click The eye is on the right of Collsion To hide it and when hiding you do not need to worry because it is only hidden, not doing anything.

An An quickly

And you lock it again Node Player:

Faculty Node

Well at the end of the post I will leave the zoom buttons with the keyboard for those who use a laptop without a mouse or the mouse button is damaged like me.

And choose Floor You pay attention to me 2 parts I have circulated in the photo

Choose Khoa

Side dark white fruit It displays Grid (square squares like Pixel Asia).

luoi

Here, this grid is a bit small so I will zoom

Let zoom up you press 3 dots next to:dau 3 cham

Choose the last one Configure Snap. Change GIRD STEP wall 32-32

tang luoi

And as photos:

Tang luoi big

You can move the floor but you can see that it does not have the right umbrella so Godot has given us another function that is Move in Pixel.

In the side Turn on Pixel You press in the floor and then turn it on:

convert

Our floor will then move in pixels

And you put it down to make the floor move

Under the photo you pay close attention, see a blue umbrella, the umbrella is our screen, remember to put Floor inside this umbrella.

Here I create 1 more Node Node Name is Wall And there contains Floor and Floor I change to 01

Wall

You put the position for Floor then click on the 01 Press the combination Ctrl + D It will double out and in the Floor 01 place you pull out is not understood, then look at the photo:

Double

Nhan Doi

Now pull out

glue

It will produce 2 pieces

2 Cai

So 2 of you can do continuously to create a longer moving floor

But before creating the floor, you need to check whether the collset is equal or not to check the collability of 01 and 02

face -to -life

Like mys, it is not very tight but the player still moves deliciously. If your deviations, adjust it to be flat.

Now create many,

I have finished creating:

I make a lotRunning the program you will see this:

Chay program

It looks quite ugly, right? But do not worry you just learn the basics to do it and this is just a guide, but the first lesson will guide you to create a player and a complete tilemap and even background, enemy too .

You can move it down and will see it will be blocked by Floor

And so you have created the moving surface, then the next is gravity.

Gravity:

When it comes to gravity, who doesn't know 😀 What makes us move easily.

To create gravity, you go to the Player script.

Declare variables:

Declare an additional gravity variable assigned it by 20

Khai BienIn Physics code for me as follows

Physics Code

Chuyendong It is what helps us move along the coordinate axis X, Y: Y is down, X It is right.

here chuyendong.y Meaning using a transformer to call the axis because we declare it chuyendong = Vector2() mean chuyendong It is allowed to use the X axis, Y and here we call the Y axis to move down by chuyendong | chuyendong.y + = tocdo means chuyendong.y = chuyendong + inluc

And it means when chuyendong The y + axis with inluc is 20, it will move down with 20 times gravity.

And run the game:

Chay Game 2

We will see it falls down and the collision of floor it is an obstacle for our player not to let the player fall down.

If your movement is like me:

convert

Then you will find it impossible to move up when pressing the arrow

And next is dance.

Dance

To code the dance part, you will code like me.

Delete if input up and if input down Go

nhay 1

And change

if input ui_left thành > elif input.is_action ui_left

And the code adds 1 part Else:

else:

Moting X axis is 0 || = 0, not += offline (I will write like this for you to understand and code it and also reform your code)

After the code you press F6 running the game, it will see it can move to the left and after stopping the movement will stand still.

Next to the jumping section.

Declare yourself a variable:

Nhaycao and assign it by -500

Why assign it by -500 Simply because when you create a gravity, our Player will fall down according to the axis, right? So here we assign -500 that it will move up in the opposite direction to the gravity when jumping to a certain height because inluc is always assigned by 20, so after dancing it will force your player down.

You declare a variable UP = Vector2(0, -1)

nhay 2

Variable Upload This is a variable to help you jump up 0, -1 || 0 is the X axis, -1 is the Y axis

Next code for yourself the image:

nhay 3

if is_on_floor This means that when you are on the floor (Floor we have created) and only when it is on the floor it can do it.

if input ui_up Then read the previous articles also know

 chuyendong.y += nhaycao To be: chuyendong Call the axis and assign it by variables nhaycao When you press the arrow key and when assigned it will jump on why? Then I explained in the declaration of variables

À in the part Move_and_slide () Add for me Upload

nhay 4

Note:

Some notes when code:

In the IF statement you can notice the character> | Fuzzy on the right of the command is the arrangement of the statements

Means the IF command that you go down to the code without> | Then it will not do this as this is not done

> | IF

> | Chuyendong = 0

Then it cannot be done and reported

If this is this:

> | IF

> | > | chuyendong = 2

Then it will work offline

How to move the sensing and zoom key for those who spoil the mouse roller or use a laptop:

  • Ctrl + – (sign – that): zoom out
  • Ctrl + + (sign + that): zoom in

Click between the surrounding or right mouse

Here you will see 3 white

nhay 5

  • The first one (4 arrows): Move Sprite
  • The second one: Turn the Sprite or press Ctrl to rotate
  • The third: zooming in or zooming in the sprite

So the next post will be about Tilemap and Tileset then will then go to the character's motion.

Deathgm!

Previous Post

Instructions for downloading and installing Bing Wallpaper on Microsoft Store

Next Post

How to find files on Windows super fast with search filter

AnonyViet

AnonyViet

Related Posts

How to detect IRQ conflict – Hardware conflict on Windows
Tips

How to detect IRQ conflict – Hardware conflict on Windows

May 13, 2025
How to use Auto Share Facebook to increase the article sharing
Tips

How to use Auto Share Facebook to increase the article sharing

May 12, 2025
Instructions for installing Facebook Lite on super light iPhone
Tips

Instructions for installing Facebook Lite on super light iPhone

May 10, 2025
Download Vietnamese Pascal Video course for beginners
Tips

Download Vietnamese Pascal Video course for beginners

May 9, 2025
How to download and delete your information on Google
Tips

How to download and delete your information on Google

May 8, 2025
How does the police ask Facebook to provide criminal data?
Tips

How does the police ask Facebook to provide criminal data?

May 7, 2025
Next Post
How to find files on Windows super fast with search filter

How to find files on Windows super fast with search filter

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Lucida: Download SoundCloud, Tidal for free, no advertising

Lucida: Download SoundCloud, Tidal for free, no advertising

May 13, 2025
How to detect IRQ conflict – Hardware conflict on Windows

How to detect IRQ conflict – Hardware conflict on Windows

May 13, 2025
Learn about En81 safety standards for home elevators

Learn about En81 safety standards for home elevators

May 12, 2025
Change super easy Windows folder icon

Change super easy Windows folder icon

May 12, 2025
Lucida: Download SoundCloud, Tidal for free, no advertising

Lucida: Download SoundCloud, Tidal for free, no advertising

May 13, 2025
How to detect IRQ conflict – Hardware conflict on Windows

How to detect IRQ conflict – Hardware conflict on Windows

May 13, 2025
Learn about En81 safety standards for home elevators

Learn about En81 safety standards for home elevators

May 12, 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

Lucida: Download SoundCloud, Tidal for free, no advertising

Lucida: Download SoundCloud, Tidal for free, no advertising

May 13, 2025
How to detect IRQ conflict – Hardware conflict on Windows

How to detect IRQ conflict – Hardware conflict on Windows

May 13, 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 bongdaso

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply
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 bongdaso