• 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

[Tạo 2D Platformer Game với Godot] Part 11: Attack of the enemy

AnonyViet by AnonyViet
January 27, 2023
in Tips
0

In this part I will show you how to set up attack on enemies and in the next part I will show you how to damage/kill enemies, player.

Join the channel Telegram of the AnonyViet 👉 Link 👈

Attack setting

[Tạo 2D Platformer Game với Godot]  Part 10: Attack of the Enemy

In the previous section, I showed you how to set up the enemy and in it the above code is used to determine when it meets the wall and it will turn around.

But here when it meets the Player, it also turns around so we have to determine that when it hits the wall and it’s not the Player, it will turn around.

And vice versa, if I collide with a wall and it’s a Player, I’ll make the enemy’s child attack.

Add node

[Tạo 2D Platformer Game với Godot]  Part 11: Attack of the enemy 9

You add yourself a raycast node named XacDinhPlayer (this raycast node I use to determine if the Player is standing in front of the enemy, it will attack).

[Tạo 2D Platformer Game với Godot]  Part 11: Enemy's Attack 10

Done, you adjust to horizontal and the raycast arrow should not collide with CollisionShape2D.

You turn it on and adjust the Cast To.

var dangtancong = false
func _physics_process(delta):
    if dangtancong == false:
        chuyendong.x = tocdo * huong_dichuyen
        chuyendong.y += trongluc
        chuyendong = move_and_slide(chuyendong,Vector2.UP)
        animation.play("dichuyen")
        
        if $RayCast2D.is_colliding() == false:
            huong_dichuyen = huong_dichuyen * -1
            scale.x = scale.y * huong_dichuyen
        
        if is_on_wall() and $XacDinhPlayer.is_colliding() == false:
            huong_dichuyen = huong_dichuyen * -1
            scale.x = scale.y * huong_dichuyen
    
    var coll = $XacDinhPlayer.get_collider()
    if coll != null and coll.name == "Player" and dangtancong == false:
        dangtancong = true
        animation.play("tancong")

I will have the same code as Player’s attack.

I omitted the moving part if dangtancong == false: is to move if not in attack mode and vice versa.

Current if is_on_wall() and $XacDinhPlayer.is_colliding() == false: then i add $XacDinhPlayer.is_colliding() == false is to determine that when it encounters a wall, if it’s a Player, it doesn’t rotate and vice versa.

Current var coll = $XacDinhPlayer.get_collider() I will create a variable and assign it as $XacDinhPlayer.get_collider() là jaw get_collider() allow me to identify RayCast which node is colliding with, I will assign the colliding node to the coll variable.

Current if coll != null and coll.name == "Player" and dangtancong == false: I check if col has been assigned with a node and the name is “Player” and not in attack state, it will perform the attack.

func _on_AnimatedSprite_animation_finished():
    if animation.animation == "tancong":
        dangtancong = false

[Tạo 2D Platformer Game với Godot]  Part 11: Attack of the Enemy 11 [Tạo 2D Platformer Game với Godot]  Part 11: Attack of the enemy 12 [Tạo 2D Platformer Game với Godot]  Part 11: Attack of the Enemy 13

I thought it was similar to the Player side, I needed to add a function to determine when the animation ended dangtancong = false by connecting the signal.

[Tạo 2D Platformer Game với Godot] Part 11: Attack of the enemy

And this is the final result.

Summary

So I’ve finished showing you how to do it, if you have any questions, please Join Godot Community Group VN or Anonyviet Community for answers,

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

Tags: AttackEnemyGameGodotPartPlatformertạovới
Previous Post

Vozflix: Free high quality movie watching app

Next Post

6 super cool ways to increase the speed of super fast WIFI network

AnonyViet

AnonyViet

Related Posts

Instructions on how to create POV product review videos using Flow
Tips

Instructions on how to create POV product review videos using Flow

July 13, 2026
How to fix “This PC can’t run Windows 11” error This PC doesn’t meet the minimum system requirements
Tips

How to fix “This PC can’t run Windows 11” error This PC doesn’t meet the minimum system requirements

July 13, 2026
How to fix Windows 11 error of not being able to install .Net Framework 3.5
Tips

How to fix Windows 11 error of not being able to install .Net Framework 3.5

July 11, 2026
How to encrypt messages with GenZ’s smiley face icon
Tips

How to encrypt messages with GenZ’s smiley face icon

July 10, 2026
Download the Copyright-Free Music app for Cafes now
Tips

Download the Copyright-Free Music app for Cafes now

July 9, 2026
Multcloud – Manage, copy, and move data between Cloud Drives
Tips

Multcloud – Manage, copy, and move data between Cloud Drives

July 9, 2026
Next Post
6 super cool ways to increase the speed of super fast WIFI network

6 super cool ways to increase the speed of super fast WIFI network

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted

Recent News

Instructions on how to create POV product review videos using Flow

Instructions on how to create POV product review videos using Flow

July 13, 2026
How to fix “This PC can’t run Windows 11” error This PC doesn’t meet the minimum system requirements

How to fix “This PC can’t run Windows 11” error This PC doesn’t meet the minimum system requirements

July 13, 2026
Compact design, durable battery, excellent camera: Review of OPPO Reno 16 Pro 5G

Compact design, durable battery, excellent camera: Review of OPPO Reno 16 Pro 5G

July 12, 2026
Download the free 3D Pinball Space Cadet game on the App Store now

Download the free 3D Pinball Space Cadet game on the App Store now

July 12, 2026
Instructions on how to create POV product review videos using Flow

Instructions on how to create POV product review videos using Flow

July 13, 2026
How to fix “This PC can’t run Windows 11” error This PC doesn’t meet the minimum system requirements

How to fix “This PC can’t run Windows 11” error This PC doesn’t meet the minimum system requirements

July 13, 2026
Compact design, durable battery, excellent camera: Review of OPPO Reno 16 Pro 5G

Compact design, durable battery, excellent camera: Review of OPPO Reno 16 Pro 5G

July 12, 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 on how to create POV product review videos using Flow

Instructions on how to create POV product review videos using Flow

July 13, 2026
How to fix “This PC can’t run Windows 11” error This PC doesn’t meet the minimum system requirements

How to fix “This PC can’t run Windows 11” error This PC doesn’t meet the minimum system requirements

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