How to make area2d to detect 1 area if they entered at the same time

Godot Version

4.3

Question

Hi i have this problem when enemy entered my area2d at the same time they both deal damage and my player area2d detect both i have disable collision upon entered but did not fix the prob iw want to detect one damage at a time even they entered at the same time. Thanks in advance :smile:

Create a variable like
var vulnerable = true
and attach a timer node when you got hit by enemy make
vulnerable = false
and then start timer when timer is out attack a signal and in signal make the player vulnerable again

By this way you can achieve what you want. Try and let me know.

1 Like

i have vulnerable time but when enemy entered at the same time or im in the middle of both enemy my collision disable but take both damage

idk how to implement this if both bodies entered at the same time or im in the middle of their collision i will only detect 1 damage or take 1 collision and ignore the other 1

In video I can not see the functionality how the hit function actually works. can you share the code for hit

you can check how many body entered in player or colide by player at instance of time and by this if they are more than one than you only run the hit function by once.

1 Like

sorry my bad im new to godot. Thanks in advance for helping me!

i will try this. Thanks!

It’s OK … :innocent:

how ? or how to implement ? thanks!

extends Area2D

var count = 0

Called when the node enters the scene tree for the first time.

func _ready() β†’ void:
pass # Replace with function body.

Called every frame. β€˜delta’ is the elapsed time since the previous frame.

func _process(delta: float) β†’ void:
position = get_global_mouse_position()
print(count)

func _on_area_entered(area: Area2D) β†’ void:
count = count + 1

func _on_area_exited(area: Area2D) β†’ void:
count = count - 1

i just implement this and it works for me hope you find it helpfull.

1 Like

this way you can check how many enemy entered in your area

i will try this. Thanks Thanks !

Thanks a lot this helps me btw i post it here how did it go this var u told was true thanks so much!!! i just put some code to it Thanks !!!

1 Like

Happy that it works. :innocent:

i post it here maybe one day someone bump to this prob Thanks alot sunnanabdullah!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.