# CameraPivot.gd
# Steuert die Third-Person-Kamera: Maussteuerung (RMB), Zoom per Mausrad
extends Node3D

@export var sensitivity = 0.3   # Mausempfindlichkeit
@export var min_pitch = -40.0   # Maximale Neigung nach unten
@export var max_pitch = 20.0    # Maximale Neigung nach oben
@export var min_zoom = 5.0      # Minimale Kameraentfernung
@export var max_zoom = 20.0     # Maximale Kameraentfernung
@export var zoom_speed = 1.0    # Zoom-Geschwindigkeit pro Mausrad-Schritt

var pitch = 0.0

@onready var camera = $Camera3D

func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

func _input(event):
	# RMB gehalten: Kamera drehen
	if event is InputEventMouseMotion and Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
		get_parent().rotate_y(deg_to_rad(-event.relative.x * sensitivity))
		pitch -= event.relative.y * sensitivity
		pitch = clamp(pitch, min_pitch, max_pitch)
		rotation_degrees.x = pitch

	# Mausrad: Zoom
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
			camera.position.z = clamp(camera.position.z + zoom_speed, min_zoom, max_zoom)
		if event.button_index == MOUSE_BUTTON_WHEEL_UP:
			camera.position.z = clamp(camera.position.z - zoom_speed, min_zoom, max_zoom)
