• 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 10: Create In-Game Enemies with Godot – Part 1

AnonyViet by AnonyViet
February 2, 2023
in Tips
0

In this article, I will guide you to create enemies for our characters with Godot game programmer. Enemies will cause the character to lose blood or you have to fight the enemy. And this part has some parts that can be very difficult and unsuccessful, so be prepared.

Join the channel Telegram belong to AnonyViet 👉 Link 👈

And let’s get started.

Creating Enemies in Godot

First we will create a button KinematicBody2D change name to enemy. LIVE enemy > more AnimatedSprite because it is of form 1 and Collision gives it as normal.

If you are using anonyviet’s assets, there are enemy assets at: asset-player > NPC > enemy assets

Asset download link

You can choose any one.

Create SpriteFrame new

Create Animation is move

[Lập Trình Game] Lesson 10: Create In-Game Enemies with Godot – Part 1

Here is the blurry picture, please re-import it

I have re-imported it and it looks better

image of enemies in game using godot . programming

Next set collision for it, here I set below not set above so that the upper part can let the character jump up and destroy it.

destroy the enemy

Lock it and create a new script and this script will be named enemy

We will create the following variables

const vitri = 1
const chuyendong = vector2
const tocdo = tùy bạn
const trongluc = tùy bạn
const  FLOOR = Vector2(0,-1)

here const is the statement used to lock the number, that is, when you declare a variable with const, it will lock that number and never be able to edit its value.

emeny enemy movement code using godot

Physical motion code

Next we will create a physical motion function

And will code like this

Assign change the x-axis = with tocdo * with vitri (* leave positive speed on the right and negative speed on the left)

Call the animation just created above: $AnimatedSprite.play(“tênanmation’)

Assign chuyendong trục y += trongluc

And call the move_and_slide command so that the enemy can move.

And here we will need a function for the enemy to detect the wall and it will move in reverse.

Godot Physical Motion Code

For example: The enemy moves to the wall, then detects that wall and then it will move back. It’s like when you reach the wall, you will simply turn around.

And we will use the if statement to check the wall: if is_on_wall():

inside if wall would be: vitri = vitri * -1

Above you have seen tocdo * vitri then positive speed is on the right and negative speed will be on the left when vitri * with -1 then it will reverse and the enemy will move in reverse when hitting the wall and right again vice versa.

And it was successful, but you notice that our enemy doesn’t change direction but stays in one direction and now we will correct it.

You code like this

if vitri == 1: (vitri = 1 = positive number where positive = move to the right)

$AnimatedSprite.flip_h = false (flip_h is the command used to rotate the sprite to the right or left)

else: (opposite of above)

$AnimatedSprite.flip_h = true (flip_h = false is it won’t rotate will stay the same,true = vice versa)

Programming the villain in the game

And it moved backwards

create enemies to destroy in godot game design

Ok so that’s the end of part 1, creating enemies for the character. Part 2 will help you code the enemy to move back and forth on the map as shown below

enemy character

When you make those blocks the enemies won’t move back and forth and that’s why there will be Part 2

And Part 3 will help you create, hp, damage for the enemy ^^.

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

Tags: createEnemiesGameGodotInGamelậpLessonParttrình
Previous Post

Download RaiDrive Full Key – Make Google Drive Your Own Drive

Next Post

How to make photo video disappear on phone with Meitu

AnonyViet

AnonyViet

Related Posts

How to get 60 days of free web hosting without a card
Tips

How to get 60 days of free web hosting without a card

November 25, 2026
How to cancel Facebook Plus package to avoid automatic renewal
Tips

How to cancel Facebook Plus package to avoid automatic renewal

November 23, 2026
How to unlock iPhone Duo face on iOS 27.3 Beta 2
Tips

How to unlock iPhone Duo face on iOS 27.3 Beta 2

November 23, 2026
Naykia: App saves posts across multiple platforms, keeping the post intact even if the original post is deleted
Tips

Naykia: App saves posts across multiple platforms, keeping the post intact even if the original post is deleted

November 22, 2026
Free CNSF certification exam guide from Red Team Leaders
Tips

Free CNSF certification exam guide from Red Team Leaders

November 21, 2026
Instructions for registering Google AI Pro for 2 years for free until 2028
Tips

Instructions for registering Google AI Pro for 2 years for free until 2028

November 21, 2026
Next Post
How to make photo video disappear on phone with Meitu

How to make photo video disappear on phone with Meitu

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted

Recent News

Co Con Suet Tre: Game to practice Vietnamese, English, Chinese pronunciation by voice

Co Con Suet Tre: Game to practice Vietnamese, English, Chinese pronunciation by voice

November 27, 2026
The truth about POCO X8s – What are the limitations behind the Snapdragon 7 Gen 4 chip that you need to know?

The truth about POCO X8s – What are the limitations behind the Snapdragon 7 Gen 4 chip that you need to know?

November 27, 2026
How to book train tickets using VNeID is extremely easy, you should know

How to book train tickets using VNeID is extremely easy, you should know

November 26, 2026
Vietnam static residential proxy: How to choose and use the service

Vietnam static residential proxy: How to choose and use the service

November 26, 2026
Co Con Suet Tre: Game to practice Vietnamese, English, Chinese pronunciation by voice

Co Con Suet Tre: Game to practice Vietnamese, English, Chinese pronunciation by voice

November 27, 2026
The truth about POCO X8s – What are the limitations behind the Snapdragon 7 Gen 4 chip that you need to know?

The truth about POCO X8s – What are the limitations behind the Snapdragon 7 Gen 4 chip that you need to know?

November 27, 2026
How to book train tickets using VNeID is extremely easy, you should know

How to book train tickets using VNeID is extremely easy, you should know

November 26, 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

Co Con Suet Tre: Game to practice Vietnamese, English, Chinese pronunciation by voice

Co Con Suet Tre: Game to practice Vietnamese, English, Chinese pronunciation by voice

November 27, 2026
The truth about POCO X8s – What are the limitations behind the Snapdragon 7 Gen 4 chip that you need to know?

The truth about POCO X8s – What are the limitations behind the Snapdragon 7 Gen 4 chip that you need to know?

November 27, 2026
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

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

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

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