class_name PlayerCameraController extends Node3D

@export var target : Node3D
@onready var camera = $Camera3D
var lookInput : Vector2 = Vector2.ZERO

func _input(event):
	if event is InputEventMouseMotion:
		lookInput.x += event.relative.y
		lookInput.y += event.relative.x
		return

	var zoom = .0
	if event.is_action_released("zoom_in"):
		zoom -= .2
	if event.is_action_released("zoom_out"):
		zoom += .2

	camera.position.z = clamp(camera.position.z + zoom, 0, 4)

func _process(delta):
	lookInput += Input.get_vector('look_left','look_right', 'look_down', 'look_up')

	global_position = target.global_position

	rotation.x = clamp(rotation.x - lookInput.x * delta * 0.3, PI*-0.48, PI*0.48)
	rotation.y -= lookInput.y * delta * 0.3

	lookInput = Vector2.ZERO
