• 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

Creating 2D Platformer Game with Godot]Part 8: Enemy Design

AnonyViet by AnonyViet
January 27, 2023
in Tips
0

In the previous section, I showed you how to create the most basic enemy, in this part I will show you how to make the enemy move on a floating surface.

Join the channel Telegram of the AnonyViet 👉 Link 👈

Enemy

Creating 2D Platformer Game with Godot]Part 8: Enemy Design

With the surface like above, I guarantee that when your enemy moves to one of the two outer corners it will drop but usually in platformet games when it moves to the corner it will return like and hit the wall in the front part.

So in this section I will show you how to do this.

Add node

First, you add yourself a new node, RayCast2D (this is the node used to query for targets that collide with rays).Creating a 2D Platformer Game with Godot]Part 8: Enemy Design 9

This is a raycast and I’m going to use it to check if I’ve reached the corner I’ll call the enemy to turn around.Creating a 2D Platformer Game with Godot]Part 8: Enemy Design 10

I’ll make it shorter and turn it on.

Creating a 2D Platformer Game with Godot]Part 8: Enemy Design 11

func _physics_process(delta):
    
    chuyendong.x = tocdo * huong_dichuyen
    chuyendong.y += trongluc
    chuyendong = move_and_slide(chuyendong,Vector2.UP)
    animation.play("dichuyen")
    
    if is_on_wall():
        huong_dichuyen = huong_dichuyen * -1
        scale.x = scale.y * huong_dichuyen
    
    if $RayCast2D.is_colliding() == false:
        huong_dichuyen = huong_dichuyen * -1
        scale.x = scale.y * huong_dichuyen

Here, I only added 3 lines of code, not much more.

First, the if line:

  • I’m going to call the raycast node and check if it’s colliding with something, if not then I’ve reached the corner then come back.
  • The remaining 2 lines are used to rotate the enemy.
  • the line scale.x = … actually you can leave the if outside, but not in the function, but I don’t because to optimize it, I put it in the if statement, so it only runs when it happens. If you leave it out, it always runs -> what the result is, you can guess.

Creating 2D Platformer Game with Godot]Part 8: Enemy Design

This is the result after I run the game.

How it works

If you do not understand, I will explain in more detail here.Creating a 2D Platformer Game with Godot]Part 8: Enemy Design 13

Here is the enemy when it’s not out of the corner, and the Raycast it is colliding with the tilemap as shown in the image.

Creating a 2D Platformer Game with Godot]Part 8: Enemy Design 14

And here is the enemy, when it reaches the corner, you see that the raycast has come out of the tilemap (the raycast collides at the sharp corner of the arrow), when it goes out, it will not collide with anything Also, in the script, I added an if to check if it doesn’t collide, then go back.

Summary

So I have guided you through how to create the most basic character, in the next part will be moving between levels, killing enemies.

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

Tags: creatingDesignEnemyGameGodotPartPlatformer
Previous Post

How to check File’s Virus before Downloading with VirusTotal

Next Post

How to change Voice when playing Game on phone

AnonyViet

AnonyViet

Related Posts

Windows 7/8.1/10 users will be upgraded to Windows 11 for free
Tips

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving ChatGPT Plus for 1 month for free in 2026
Tips

Instructions for receiving ChatGPT Plus for 1 month for free in 2026

July 28, 2026
Some reasons I don’t like Windows 11
Tips

Some reasons I don’t like Windows 11

July 27, 2026
Instructions on how to get free Facebook white ticks
Tips

Instructions on how to get free Facebook white ticks

July 27, 2026
Collection of Windows 11 wallpapers for computers and phones
Tips

Collection of Windows 11 wallpapers for computers and phones

July 26, 2026
Don’t install leaked Windows 11
Tips

Don’t install leaked Windows 11

July 25, 2026
Next Post
How to change Voice when playing Game on phone

How to change Voice when playing Game on phone

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted

Recent News

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving the free Certified LLM Security Expert certificate

Instructions for receiving the free Certified LLM Security Expert certificate

July 30, 2026
MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

July 29, 2026
What is quantum resistant cryptography? Why must the Internet change?

What is quantum resistant cryptography? Why must the Internet change?

July 29, 2026
Windows 7/8.1/10 users will be upgraded to Windows 11 for free

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving the free Certified LLM Security Expert certificate

Instructions for receiving the free Certified LLM Security Expert certificate

July 30, 2026
MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

July 29, 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

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving the free Certified LLM Security Expert certificate

Instructions for receiving the free Certified LLM Security Expert certificate

July 30, 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