extends Camera3D @export var sensitivity: float = 0.002 @export var smooth_speed: float = 15.0 var target_yaw: float = 0.0 var target_pitch: float = 0.0 func _ready() -> void: target_yaw = rotation.y target_pitch = rotation.x # Capture the mouse immediately so you don't need to click to look around Input.mouse_mode = Input.MOUSE_MODE_CAPTURED func _input(event: InputEvent) -> void: # Allows you to hit 'Escape' to free your mouse cursor if needed if event.is_action_pressed("ui_cancel"): if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: Input.mouse_mode = Input.MOUSE_MODE_VISIBLE else: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED # Always looks around when the mouse moves (as long as it's captured) if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: target_yaw -= event.relative.x * sensitivity target_pitch -= event.relative.y * sensitivity target_pitch = clamp(target_pitch, deg_to_rad(-89), deg_to_rad(89)) # Zoom implementation (Clamped safely between 10 and 75 FOV) if event is InputEventMouseButton: if Input.is_key_pressed(KEY_ALT): if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: fov = clamp(fov + 5, 10, 75) elif event.button_index == MOUSE_BUTTON_WHEEL_UP: fov = clamp(fov - 5, 10, 75) func _process(delta: float) -> void: # Smooth Rotation rotation.y = lerp_angle(rotation.y, target_yaw, smooth_speed * delta) rotation.x = lerp(rotation.x, target_pitch, smooth_speed * delta)