Godot Version
`4.3
Question
Hello,
I have an enemy that performs an attack animation when the player enters an area. I have set up the area2d to detect when the players area hitbox enters and exits, and have a print to tell when the area is entered and exited:
func _on_ehurtbox_area_entered(area: Area2D) -> void:
if "PHurtbox" in area.name CanAttack:
print("Area entered")
Attacking = true
Move = 0
timer.start()
Combat.Damage.emit(ATTK)
animation.play("attack")
Attacking = false
func _on_ehurtbox_area_exited(area: Area2D) -> void:
if "PHurtbox" in area.name:
print("area left")
return
I also have it set up so that when the player attack hitbox touches the enemy hitbox, the enemy will be knocked back, play a damage animation, and then begin running towards the player again.
func UpdateHP():
if hit:
CanAttack = false
Move = 0
stuntimer.start()
var tween = create_tween()
tween.tween_property(self, "position",position + Vector2(400, -20), 0.2)
HP = HP - DamageTaken
DamageTaken = 0
hit = false
I have UpdateHP running in the physics process, and have the animations set to play based on velocity and if other animations are playing. The animations all work fine, and before the player attacks the enemy, it will perform its attack and detect the player hitbox no problem.
However, after the player attacks the enemy, it no longer detects the player area2d hitbox. The player still detects the hitbox because they do their knockback, but the enemy attack animation no longer plays or runs the damage script. I have no idea how to fix this or why it’s happening.
I also know now that the best way to handle this is with state machines, which I’m learning, but for the sake of finishing off this small prototype, I’d like to know what I’m doing wrong.
If I need to post more code, please let me know, I’m new to posting.
Thanks in advance
edited to properly show the code and add some clarity.