Godot Version
`4.1.2
What the code should do is kill the enemy when its area detects a bullet group node, but even though it doesn’t have any type of error, the enemy doesn’t die. I thought it was because the bullet was destroyed when it touched the enemy’s area, but it didn’t.
enemie code:
@export var movement_speed = 40.0
@onready var planta = get_tree().get_first_node_in_group("planta")
@onready var sprite = $Sprite2D
@onready var vida = 9
func _physics_process(_delta):
if is_instance_valid(planta):
var direction = global_position.direction_to(planta.global_position)
velocity = direction*movement_speed
move_and_slide()
if direction.x > 0:
sprite.flip_h = false
elif direction.x < 0:
sprite.flip_h = true
else:
planta = get_tree().get_first_node_in_group("planta")
move_and_slide()
func _ready():
$lil.play("move")```
func _on_area_2d_area_entered(_area):
if _area.is_in_group("planta_area"):
$lil.play("attack")
elif _area.is_in_group("bala"):
vida -= 9
elif vida == 0:
queue_free()
func _on_area_2d_area_exited(_area):
$lil.play("move")