extends KinematicBody2D # class member variables go here, for example: # var a = 2 # var b = "textvar" var ani_sprite var health = 100 func _ready(): # Called every time the node is added to the scene. # Initialization here ani_sprite = get_node("AnimatedSprite") set_fixed_process(true) func take_damage(damage): health -= damage func _fixed_process(delta): if health <= 0: queue_free() var target = get_parent().get_node("Player") var angle = get_angle_to(target.get_global_pos()) var move_dir = Vector2(0, 1).rotated(angle) if move_dir.x > 0: ani_sprite.set_animation("right") elif move_dir.y > 0: ani_sprite.set_animation("down") elif move_dir.x < 0: ani_sprite.set_animation("left") elif move_dir.y < 0: ani_sprite.set_animation("up") # actually move too move(move_dir)