As it says in the title I'm trying to build a damage system but my enemy's health won't go down to zero. If someone could tell me what I am doing wrong I would really appreciate it!
extends KinematicBody2D
# right is 1 left -1
#variable for enemy movement
const Speed = 150
var Health = 5
var Velocity = Vector2()
const Floor = Vector2(0,-1)
var Direction = 1
onready var enemy_health = 1
func enemy_walking():
Velocity.x = Speed * Direction
# next line animates the enemy walking left or right
if Direction == 1:
$AnimatedSprite.flip_h = false
else:
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("walking")
Velocity = move_and_slide(Velocity, Floor)
if is_on_wall():
Direction = Direction * -1
# next line applies physics and movement to the enemy skeleton
func _physics_process(delta):
enemy_walking()
func _on_hurtbox_area_entered(area):
if area.is_in_group("sword"):
enemy_health -= 1
elif enemy_health == 0:
$AnimatedSprite.play("Dying")
func _on_AnimatedSprite_animation_finished():
if $AnimatedSprite.animation == "Dying":
queue_free()