Files
brackeys-knight/scripts/slime.gd

32 lines
727 B
GDScript

extends CharacterBody2D
@export var speed = 60
var direction = 1
@onready var ray_cast_right: RayCast2D = $RayCastRight
@onready var ray_cast_left: RayCast2D = $RayCastLeft
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
# Apply gravity
if not is_on_floor():
velocity += get_gravity() * delta
if ray_cast_right.is_colliding():
direction = -1
animated_sprite.flip_h = true
if ray_cast_left.is_colliding():
direction = 1
animated_sprite.flip_h = false
position.x += direction * speed * delta
move_and_slide()
func _on_hit_box_killed() -> void:
queue_free()