• 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 a 2D Platformer Game with Godot]Part 8: Enemy Design 12

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

4 ways to fix bluetooth connectivity on Windows 11
Tips

4 ways to fix bluetooth connectivity on Windows 11

August 8, 2025
How to know the computer is tracked and processed by Keylogger
Tips

How to know the computer is tracked and processed by Keylogger

August 7, 2025
Opal: Create applications who do not need to write code
Tips

Opal: Create applications who do not need to write code

August 3, 2025
How to activate a new Start menu on Windows 11
Tips

How to activate a new Start menu on Windows 11

July 29, 2025
Intellgpt: AI tool for osint and data science
Tips

Intellgpt: AI tool for osint and data science

July 28, 2025
How to create Google Ai Pro 12 months free with Indian student account
Tips

How to create Google Ai Pro 12 months free with Indian student account

July 27, 2025
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
Inline Feedbacks
View all comments

Recent News

How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
Wowhay.com – The door opens the world of modern knowledge and network culture

Wowhay.com – The door opens the world of modern knowledge and network culture

August 13, 2025
Instructions on how to fix Screen Time Limited Reached on RoBlox

Instructions on how to fix Screen Time Limited Reached on RoBlox

August 13, 2025
How to install GPT-suns on who do not need the Internet

How to install GPT-suns on who do not need the Internet

August 12, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
Wowhay.com – The door opens the world of modern knowledge and network culture

Wowhay.com – The door opens the world of modern knowledge and network culture

August 13, 2025
Instructions on how to fix Screen Time Limited Reached on RoBlox

Instructions on how to fix Screen Time Limited Reached on RoBlox

August 13, 2025
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 to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
Wowhay.com – The door opens the world of modern knowledge and network culture

Wowhay.com – The door opens the world of modern knowledge and network culture

August 13, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí mm88 8XBET mm88 trang chủ new88

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

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí mm88 8XBET mm88 trang chủ new88

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