• 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

3 OCR Tools Extract Text from Images without Retyping
Tips

3 OCR Tools Extract Text from Images without Retyping

November 8, 2025
Ways hackers use to hack your Facebook and how to fix it
Tips

Ways hackers use to hack your Facebook and how to fix it

November 7, 2025
Create your own Font using your Handwriting
Tips

Create your own Font using your Handwriting

November 6, 2025
Share White Hat Hacker Course – The Complete Ethical Hacking Course
Tips

Share White Hat Hacker Course – The Complete Ethical Hacking Course

November 5, 2025
Instructions on how to get 1 year of ChatGPT Go for free
Tips

Instructions on how to get 1 year of ChatGPT Go for free

November 4, 2025
Instructions for creating your own Chrome Extension using Scratch
Tips

Instructions for creating your own Chrome Extension using Scratch

November 4, 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

Instructions for downloading Anh Hai’s Pho Shop game on Android

Instructions for downloading Anh Hai’s Pho Shop game on Android

November 8, 2025
Download training materials on Applying AI in teaching and learning in 2025

Download training materials on Applying AI in teaching and learning in 2025

November 8, 2025
How to pay health insurance on Momo online right at home

How to pay health insurance on Momo online right at home

November 8, 2025
How to create Flycam videos from photos to sell real estate

How to create Flycam videos from photos to sell real estate

November 8, 2025
Instructions for downloading Anh Hai’s Pho Shop game on Android

Instructions for downloading Anh Hai’s Pho Shop game on Android

November 8, 2025
Download training materials on Applying AI in teaching and learning in 2025

Download training materials on Applying AI in teaching and learning in 2025

November 8, 2025
How to pay health insurance on Momo online right at home

How to pay health insurance on Momo online right at home

November 8, 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

Instructions for downloading Anh Hai’s Pho Shop game on Android

Instructions for downloading Anh Hai’s Pho Shop game on Android

November 8, 2025
Download training materials on Applying AI in teaching and learning in 2025

Download training materials on Applying AI in teaching and learning in 2025

November 8, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

new88 trang chủ shbet trang chủ f168 trang chủ qq88 nhà cái 78win

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

new88 trang chủ shbet trang chủ f168 trang chủ qq88 nhà cái 78win

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