33 lines
1.2 KiB
GDScript
33 lines
1.2 KiB
GDScript
extends Node3D
|
|
|
|
@export var mouse_sensitivity: float = 0.005
|
|
@export_range(-90.0, 0.0, 0.1, "radians_as_degrees") var min_vertical_angle: float = -PI / 2
|
|
@export_range(0.0, 90.0, 0.1, "radians_as_degrees") var max_vertical_angle: float = PI / 4
|
|
@export var min_zoom: float = 2.0
|
|
@export var max_zoom: float = 12.0
|
|
|
|
@onready var spring_arm := $SpringArm3D
|
|
|
|
|
|
func _ready() -> void:
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event is InputEventMouseMotion:
|
|
rotation.y -= event.relative.x * mouse_sensitivity
|
|
rotation.y = wrapf(rotation.y, 0.0, TAU)
|
|
rotation.x -= event.relative.y * mouse_sensitivity
|
|
rotation.x = clamp(rotation.x, min_vertical_angle, max_vertical_angle)
|
|
|
|
if event.is_action_pressed("zoom_in"):
|
|
spring_arm.spring_length = clamp(spring_arm.spring_length - 1.0, min_zoom, max_zoom)
|
|
if event.is_action_pressed("zoom_out"):
|
|
spring_arm.spring_length = clamp(spring_arm.spring_length + 1.0, min_zoom, max_zoom)
|
|
|
|
if event.is_action_pressed("toggle_mouse_capture"):
|
|
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
|
else:
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|