• 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 Godot programming – Part 1

AnonyViet by AnonyViet
January 7, 2025
in Tips
0

In this article, I will guide you how to create enemies for our characters Godot game programming. Enemies will cause the character to lose health or you will have to fight the enemy. And this part has a few parts that may be very difficult and unsuccessful, so please prepare yourself mentally.

Join the channel Telegram belong to AnonyViet 👉 Link 👈

And let's get started.

Create enemies

First create a new Sence and include the child node's 2D kinematicbody AnimatedSprite and CollsionShape2D then press Ctrl + S stay.

Creating Enemies in Godot programming

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

Link download Asset

Choose any one.

Create a new SpriteFrame

Creating Animation is move

download assets create enemies godot

If your photo is blurry Import come again

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

set collision

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

create script enemies

We will create additional variables later

var Vitri = 1
var  vantoc = Vector2.ZERO //hoặc Vector2() đều giống như nhau
var  Tocdo = tùy bạn
var Trongluc = tùy bạn
var  FLOOR = Vector2(0,-1)

Here const is the command used to lock the number, meaning that when you declare a variable with const, it will lock that number and its value can never be edited.

code create enemy enemy godot engine

Next we will create the physical motion function

And will code as follows

Assign gravity to it

vantoc.y  =  trongluc

Assign speed to it

vantoc.x  += tocdo * delta * vitri (Here * delta to reduce enemy speed)

Add move_and_slide statement to make it moveable

vantoc = move_and_slide(vantoc)

Next you will instance it outside our sense:

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

And instance it

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

Run the game and you will see it move

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

Here, I have the collsionshape visible mode, so there's nothing

Next we will code it to move left, and animate

And here I will have a command:

if is_on_wall() : is_on_wall() is a statement that returns true if the Body is on the Wall, and it only executes when called with move_and_slide

And next below if is_on_wall() we will code one more line:

vitri = vitri * -1 and this line when it touches something vitri is 1 then it will * -1 and it will move backwards

Oh, and if you run the game and see the character running slowly, check if move_and_slide has FLOOR. If not, add it. If it's there and it's still slow, adjust the speed to about 20-30.

And next we will code the animation for it

if vitri == 1:
$AnimatedSprite.flip_h = false
else:
$AnimatedSprite.flip_h = true

The 2 lines above are the 2 lines that will change the image of the enemy, flip_h = false The image will flip to the right flip_h = true is to the left

if vitri == 1 : means the position is equal to 1 and = 1 then it will move to the right but our enemy moves to the right first so flip_h will = false

And vice versa

Then you call animation move for me

$AnimatedSprite.play("Move")

How to create enemies

Mine is fine after running the game

And in the next lesson, I will guide you to create raycast so that enemies can move on the tilemap as shown below without falling.

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

Previous Post

How to investigate fines for running red lights via VNeTraffic

Next Post

How to Copy files from one Google Drive to another Google Drive super fast

AnonyViet

AnonyViet

Related Posts

Instructions to receive Claude Fable 5 for free for 30 days
Tips

Instructions to receive Claude Fable 5 for free for 30 days

June 15, 2026
Delete all Event Logs on Windows to remove traces of activity
Tips

Delete all Event Logs on Windows to remove traces of activity

June 15, 2026
Instructions for creating Minecraft-style food photos
Tips

Instructions for creating Minecraft-style food photos

June 9, 2026
Get free Cambridge courses to prepare for IELTS, Starters, Movers
Tips

Get free Cambridge courses to prepare for IELTS, Starters, Movers

June 4, 2026
How to record reaction videos with Android phones, no app needed
Tips

How to record reaction videos with Android phones, no app needed

June 1, 2026
Instructions on how to get Google AI Pro 1 year for free for new accounts
Tips

Instructions on how to get Google AI Pro 1 year for free for new accounts

June 1, 2026
Next Post
How to Copy files from one Google Drive to another Google Drive super fast

How to Copy files from one Google Drive to another Google Drive super fast

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Instructions to receive Claude Fable 5 for free for 30 days

Instructions to receive Claude Fable 5 for free for 30 days

June 15, 2026
Instructions on how to activate the new Siri on iOS 27

Instructions on how to activate the new Siri on iOS 27

June 15, 2026
Delete all Event Logs on Windows to remove traces of activity

Delete all Event Logs on Windows to remove traces of activity

June 15, 2026
Instructions on how to get the latest 200GB MultCloud for free in 2026

Instructions on how to get the latest 200GB MultCloud for free in 2026

June 14, 2026
Instructions to receive Claude Fable 5 for free for 30 days

Instructions to receive Claude Fable 5 for free for 30 days

June 15, 2026
Instructions on how to activate the new Siri on iOS 27

Instructions on how to activate the new Siri on iOS 27

June 15, 2026
Delete all Event Logs on Windows to remove traces of activity

Delete all Event Logs on Windows to remove traces of activity

June 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 to receive Claude Fable 5 for free for 30 days

Instructions to receive Claude Fable 5 for free for 30 days

June 15, 2026
Instructions on how to activate the new Siri on iOS 27

Instructions on how to activate the new Siri on iOS 27

June 15, 2026
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

6789 kv999

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

6789 kv999

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