extends Node3D

@export var rotation_speed: float = 15.0 # degrees per second
@export var rotation_limit: float = 15.0 # degrees
@export var pause_duration: float = 3.0 # seconds

var rotating_forward: bool = true
var is_paused: bool = false

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if is_paused:
		return
	
	var current_yaw = rotation_degrees.y
	var direction = 1
	if not rotating_forward:
		direction = -1
	var next_yaw = current_yaw + direction * rotation_speed * delta
	
	if rotating_forward and next_yaw >= rotation_limit:
		rotation_degrees.y = rotation_limit
		_pause_and_reverse()
	elif not rotating_forward and next_yaw <= -rotation_limit:
		rotation_degrees.y = -rotation_limit
		_pause_and_reverse()
	else:
		rotation_degrees.y = next_yaw

func _pause_and_reverse():
	is_paused = true
	rotating_forward = not rotating_forward
	await get_tree().create_timer(pause_duration).timeout
	is_paused = false
	
	
