class_name Slime extends Area2D @onready var slime_graphic: AnimatedSprite2D = $SlimeGraphic @onready var right_cast: RayCast2D = $RightCast @onready var left_cast: RayCast2D = $LeftCast @onready var left_cast_down: RayCast2D = $LeftCastDown @onready var right_cast_down: RayCast2D = $RightCastDown signal playerDamageSignal(body, slime) var SPEED: int = 100 var direction = 1 # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: position.x += direction * SPEED * delta if right_cast.is_colliding(): var collider = right_cast.get_collider() if collider is not Player: direction = -1 if left_cast.is_colliding(): var collider = left_cast.get_collider() if collider is not Player: direction = 1 if not right_cast_down.is_colliding(): direction = -1 if not left_cast_down.is_colliding(): direction = 1 if direction == -1: slime_graphic.flip_h = true else: slime_graphic.flip_h = false func _on_body_entered(body: Node2D) -> void: if body is Player: playerDamageSignal.emit(body, self)