• 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

How are Windows 11 Pro and Windows 10 Pro different?
Tips

How are Windows 11 Pro and Windows 10 Pro different?

October 23, 2026
Instructions for using CleanYourTV: Remove ads on Android TV, Google TV
Tips

Instructions for using CleanYourTV: Remove ads on Android TV, Google TV

October 23, 2026
How to use Messenger without a Facebook account
Tips

How to use Messenger without a Facebook account

October 22, 2026
The website helps you draw beautifully like TikToker Viet My
Tips

The website helps you draw beautifully like TikToker Viet My

October 21, 2026
Instructions on how to hard reset iPhone 18 Pro / iPhone 18 Pro Max
Tips

Instructions on how to hard reset iPhone 18 Pro / iPhone 18 Pro Max

October 21, 2026
Anyone can do how to increase Internet speed using CMD
Tips

Anyone can do how to increase Internet speed using CMD

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

How are Windows 11 Pro and Windows 10 Pro different?

How are Windows 11 Pro and Windows 10 Pro different?

October 23, 2026
Instructions for using CleanYourTV: Remove ads on Android TV, Google TV

Instructions for using CleanYourTV: Remove ads on Android TV, Google TV

October 23, 2026
Receive copyright for 3 Halloween software worth 0

Receive copyright for 3 Halloween software worth $150

October 23, 2026
How to use Messenger without a Facebook account

How to use Messenger without a Facebook account

October 22, 2026
How are Windows 11 Pro and Windows 10 Pro different?

How are Windows 11 Pro and Windows 10 Pro different?

October 23, 2026
Instructions for using CleanYourTV: Remove ads on Android TV, Google TV

Instructions for using CleanYourTV: Remove ads on Android TV, Google TV

October 23, 2026
Receive copyright for 3 Halloween software worth 0

Receive copyright for 3 Halloween software worth $150

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

How are Windows 11 Pro and Windows 10 Pro different?

How are Windows 11 Pro and Windows 10 Pro different?

October 23, 2026
Instructions for using CleanYourTV: Remove ads on Android TV, Google TV

Instructions for using CleanYourTV: Remove ads on Android TV, Google TV

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