extends Camera3D

@export var follow_node : Node3D
@export var follow_offset : Vector3
@export var bounds : CollisionShape3D

var aspect : float

func _ready() -> void:
	aspect = (float)(get_viewport().size.x) / (float)(get_viewport().size.y)

func _process(_delta: float) -> void:
	global_position = follow_node.global_position + follow_offset
	global_position = global_position.clamp(
		Vector3(
			bounds.position.x - (bounds.shape.size.x / 2) + (size * aspect / 2),
			bounds.position.y - (bounds.shape.size.y / 2) + (size / 2),
			-INF
		),
		Vector3(
			bounds.position.x + (bounds.shape.size.x / 2) - (size * aspect / 2),
			bounds.position.y + (bounds.shape.size.y / 2) - (size / 2),
			INF
		)
	)
