extends Node3D

#variaveis de propriedades
@export_group("Properties")
@export var target: Node3D

#variaveis de zoom
@export_group("zoom")
@export var zoom_minimum = 16
@export var zoom_maximum = 4
@export var zoom_speed = 10

#variaveis de rotação
@export_group("Rotation")
@export var rotation_speed = 120
@export var min_rotation_x = -80
@export var max_rotation_x = -10

var camera_rotation:Vector3
var zoom = 10

#atribuição da camera
@onready var Camera = $camera

#função
func _ready():
	camera_rotation = rotation_degrees #inicia a rotação

func _physics_process(delta):
	self.position = self.position.lerp(target.position, delta * 4)
	rotation_degrees = rotation_degrees.lerp(camera_rotation, delta * 6)
	
	Camera.position = Camera.position.lerp(Vector3(0, 0, zoom), 8 * delta)
	
	handle_input(delta)
	
func handle_input(delta):
	#rotação
	var input := Vector3.ZERO
	
	#seleção de inputs das teclas
	input.y = Input.get_axis("ui_left", "ui_right")
	input.x = Input.get_axis("ui_up", "ui_down")
	
	camera_rotation += input * rotation_speed * delta
	camera_rotation.x = clamp(camera_rotation.x, min_rotation_x, max_rotation_x)
	
	zoom += Input.get_axis("zoom_in", "zoom_out") * zoom_speed * delta
	zoom = clamp(zoom, zoom_maximum, zoom_minimum)
	

	
	
	
	
