class_name OrbitalCamera extends Node3D

const POSITION_ACCELERATION := 4.0

@export var target: Node3D

@export var angular_speed := 0.01

@onready var camera: Camera3D = %Camera

static var scene := preload("res://src/player/orbital_camera/orbital_camera.tscn")


func _physics_process(delta: float) -> void:
	# Update position
	global_position = global_position.lerp(target.global_position, delta * POSITION_ACCELERATION)

	# Update rotation
	camera.look_at(target.global_position)

	# Update phase angle
	rotation.y += angular_speed


static func create(_target: Node3D) -> OrbitalCamera:
	var instance: OrbitalCamera = scene.instantiate()
	instance.target = _target
	return instance
