Godot version
4.1.2
I’m having an error that the truth is that I don’t understand the enemy that I made when he dies outside the plant area it plays the death animation but when he dies in the plant area it doesn’t play the death animation and I really don’t understand the error All this happened when I deactivated the hitbox in the death animations.
“Plant” is a node that the enemy heads towards and attacks.
code:
@export var movement_speed = 65
@onready var plant = get_tree().get_first_node_in_group("plant")
@onready var sprite = $Sprite2D
@onready var life = 35
@onready var flash = $hitflash
func _physics_process(_delta):
if is_instance_valid(plant):
var direction = global_position.direction_to(plant.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:
plant = get_tree().get_first_node_in_group("plant")
move_and_slide()
func _ready():
$anim.play("move")
func _on_area_2d_area_entered(_area):
if _area.is_in_group("plant_area"):
$anim.play("attack")
set_physics_process(false)
await get_tree().create_timer(10).timeout
set_physics_process(true)
elif _area.is_in_group("bullet"):
flash.play("hit_flash")
life -= 9
if life <= 0:
set_physics_process(false)
$anim.play("death")
await get_tree().create_timer(0.8).timeout
queue_free()
func _on_area_2d_area_exited(_area):
if _area.is_in_group("plant_area"):
$anim.play("move")