extends Node2D

var target

func _process(delta):
	var dist = global_position.x - target.global_position.x
	$AnimationPlayer.seek(range_lerp(dist, 1300, -1300, 0, 1), true)
	
func _on_damage_area_body_entered(body):
	if body.has_method("apply_damage"):
		body.apply_damage(1, "damage")

func _ready():
	set_process(false)
	$body/part_1/damage_area.connect("body_entered", self, "_on_damage_area_body_entered")

func _on_VisibilityNotifier2D_viewport_entered(viewport):
	target = Global.level.get_node("actors/player")
	$AnimationPlayer.play("move")
	set_process(true)

