#Why does my enemy sometimes gets hit twice?

2 messages · Page 1 of 1 (latest)

wooden swan
#

I have this code to check for collision for bullet and remove the bullet:

func _on_area_2d_area_shape_entered(area_rid, area, area_shape_index, local_shape_index):
    var parent = area.get_parent()
    if parent.is_in_group("shot"):
        parent.queue_free()
        print("took damage")
        health -= parent.damage

It works 70% of the time but rest of the time it will damage the enemy 2 times. This could be considered a "feature" with critical hits but for my game it is important that there are no "critical hits" 😄

my bullet node:

wooden swan
#

Have no idea what caused this but all I did was make a list of bullets that have hit the enemy and if it tries to hit the enemy for the second time, the script detects that its already in the list and ignores it