• 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: Creating Enemies in Game Using Godot – Part 1

AnonyViet by AnonyViet
July 26, 2024
in Tips
0

In this article I will guide you to create enemies for our characters by Godot game programming. The enemy will make the character lose blood or you have to fight the enemy. And this part has some parts that can be very very difficult and unsuccessful, so you guys should prepare yourself mentally.

Join the channel Telegram belong to AnonyViet 👉 Link 👈

And here we go.

Creating Enemies in Godot

First we will create a button KinematicBody2D rename to enemy. LIVE enemy > more AnimatedSprite because it is type 1 and Collision for it as normal.

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

Asset download link

Choose any one.

Create SpriteFrame new

Create Animation is move

[Lập Trình Game] Lesson 10: Creating Enemies in Game Using Godot – Part 1

Here is a blurry photo, please import it again.

I reimported it and it looks better.

enemy images in game using godot programming

Next set collision for it, here I set below not above so that the top 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 command used to lock the number, meaning when you declare a variable with const, it will lock that number and its value can never be edited.

emeny enemy movement code by godot

Physical motion code

Next we will create the physical motion function

And will code as follows

Assign x-axis movement = with speed * with vitri (* positive speed will be on the right and negative speed will be 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 the enemy can move.

And here we will need a function to let the enemy detect the wall and it will move back.

godot physics motion code

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

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

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

You have seen above tocdo * vitri then positive speed will be on the right and negative speed will be on the left so when vitri * with -1 then it will reverse and the enemy will move backwards when it hits the wall and vice versa if it hits the right.

And it worked, but you notice that our enemy doesn't change direction but stays in one direction. Now we'll fix it.

You code as follows

if vitri == 1: (vitri = 1 = positive number which positive number = 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 the above)

$AnimatedSprite.flip_h = true (flip_h = false means it will not rotate and will stay the same, true = otherwise)

game villain programming

And it moved back

create enemies to destroy in godot game design

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

enemy character

When you create those blocks the enemy 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 enemies^^.

Previous Post

How to check if your phone supports 5G

Next Post

How to set virtual RAM on Windows 11

AnonyViet

AnonyViet

Related Posts

How to create a virtual Pet, a virtual character running around on the Desktop to relax
Tips

How to create a virtual Pet, a virtual character running around on the Desktop to relax

October 15, 2026
15 cách tăng tốc Windows 10 nhanh như gió
Tips

15 cách tăng tốc Windows 10 nhanh như gió

October 14, 2026
How to create Guest mode Shortcuts for Chrome and Edge
Tips

How to create Guest mode Shortcuts for Chrome and Edge

October 13, 2026
Test what breed of dog you are through 10 multiple choice questions
Tips

Test what breed of dog you are through 10 multiple choice questions

October 13, 2026
Fliqlo – Create digital clock screens on Windows and phones
Tips

Fliqlo – Create digital clock screens on Windows and phones

October 12, 2026
SynthID Detector: Genuine AI checking tool from Google
Tips

SynthID Detector: Genuine AI checking tool from Google

October 11, 2026
Next Post
How to set virtual RAM on Windows 11

How to set virtual RAM on Windows 11

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted

Recent News

Instructions for receiving pension through VNeID without going to the ward

Instructions for receiving pension through VNeID without going to the ward

October 16, 2026
MBTI, Big Five, DISC or Holland: which personality test should you choose?

MBTI, Big Five, DISC or Holland: which personality test should you choose?

October 15, 2026
How to create a virtual Pet, a virtual character running around on the Desktop to relax

How to create a virtual Pet, a virtual character running around on the Desktop to relax

October 15, 2026
Record first, choose focus later: how to use 4K 60 fps Cinema mode on iPhone 18 Pro

Record first, choose focus later: how to use 4K 60 fps Cinema mode on iPhone 18 Pro

October 15, 2026
Instructions for receiving pension through VNeID without going to the ward

Instructions for receiving pension through VNeID without going to the ward

October 16, 2026
MBTI, Big Five, DISC or Holland: which personality test should you choose?

MBTI, Big Five, DISC or Holland: which personality test should you choose?

October 15, 2026
How to create a virtual Pet, a virtual character running around on the Desktop to relax

How to create a virtual Pet, a virtual character running around on the Desktop to relax

October 15, 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

Instructions for receiving pension through VNeID without going to the ward

Instructions for receiving pension through VNeID without going to the ward

October 16, 2026
MBTI, Big Five, DISC or Holland: which personality test should you choose?

MBTI, Big Five, DISC or Holland: which personality test should you choose?

October 15, 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