extends Node2D

const SPEED=40

var direction= 1

func _physics_process(delta: float) -> void:
	if $RayCastRight.is_colliding():
		direction=-1
		$AnimatedSprite2D.flip_h=false
	if $RayCastLeft.is_colliding():
		direction=1
		$AnimatedSprite2D.flip_h=true
	position.x += direction * SPEED * delta

func _on_area_2d_area_entered(area: Area2D) -> void:
	if area.is_in_group("player"):
		get_tree().change_scene_to_file("res://scenes/died.tscn")
