Hi, I’m new to Godot and I made a game that you can run and kill your enemy with melee attack. And after I finished the player attacking function, I wanted to add a enemy attack function. So I wrote these basic lines:
if can_attack == true and dealing_with_damage == false:
$Detection_area/CollisionShape2D.disabled = true
$AttackTimer.start()
$AnimatedSprite2D.play("attack")
global.is_enemy_attacking = true
func _on_attack_timer_timeout():
global.is_enemy_attacking = false
$Detection_area/CollisionShape2D.disabled = false
if can_attack == true:
return attack()
Then the code actually worked and my player started to taking damage. But the enemy’s attacking animation didn’t worked. More precisely, the enemy stuck in only one frame of the animation. If you help, thank you in advance!
(Note: $Detection_area/CollisionShape2D.disabled means enemy can’t move while attacking)
you can go to your animation and turn on the loop (it is at the left corner of the animation bar)
if that isn’t the case add a flag to your if condition like attacking == true:
var attacking = false #add this on top of all the func
###
if can_attack == true and dealing_with_damage == false and attacking == false:
$Detection_area/CollisionShape2D.disabled = true
$AttackTimer.start()
$AnimatedSprite2D.play("attack")
global.is_enemy_attacking = true
attacking = true
func _on_attack_timer_timeout():
attacking = false
global.is_enemy_attacking = false
$Detection_area/CollisionShape2D.disabled = false
if can_attack == true:
return attack()