2 class_name PlayerCameraHandler
5 @export_range(1.0, 10.0) var camera_distance := 3.0
7 @export_range(0.0, 1.0) var mouse_sensitivity := 0.2
8 @export_range(0.0, 1.0) var mouse_sensitivity_x := 1.0
9 @export_range(0.0, 1.0) var mouse_sensitivity_y := mouse_sensitivity_x / 2
11 @export_range(0.0, 1.0) var joystick_sensitivity := 0.15
12 @export_range(0.0, 10.0) var joystick_sensitivity_x := 4.0
13 @export_range(0.0, 10.0) var joystick_sensitivity_y := joystick_sensitivity_x / 2
16 @onready var spring: SpringArm3D = $SpringArm3D
19 # Called when the node enters the scene tree for the first time.
20 func _ready() -> void:
21 spring.spring_length = camera_distance
24 # Called every frame. 'delta' is the elapsed time since the previous frame.
25 func _process(delta: float) -> void:
26 spring.spring_length = lerp(
27 spring.spring_length, camera_distance, delta
31 func update(input: InputPacket, delta: float):
32 var camera_input_direction := input.camera_input_direction
34 if input.camera_input_method == CameraInput.MOUSE:
35 camera_input_direction *= Vector2(
36 mouse_sensitivity_x, -mouse_sensitivity_y
38 elif input.camera_input_method == CameraInput.JOYSTICK:
39 camera_input_direction *= Vector2(
40 joystick_sensitivity_x, -joystick_sensitivity_y
41 ) * joystick_sensitivity
43 # vertical camera rotation
44 rotation.x += camera_input_direction.y * delta
45 rotation.x = clamp(rotation.x, -PI / 6, PI / 3)
47 # horizontal camera rotation
48 rotation.y -= camera_input_direction.x * delta