2024-02-09 23:10:51 +00:00
|
|
|
extends Node3D
|
|
|
|
|
|
|
|
@export var sensitivity: float
|
2024-02-12 15:58:17 +00:00
|
|
|
@export var min_rotation_x: float = -80.0
|
2024-02-17 11:14:21 +00:00
|
|
|
@export var max_rotation_x: float = 25.0
|
2024-02-09 23:10:51 +00:00
|
|
|
|
|
|
|
var enabled: bool
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
assert(rotation_order == EULER_ORDER_YXZ)
|
2024-02-17 11:14:21 +00:00
|
|
|
min_rotation_x = deg_to_rad(min_rotation_x)
|
|
|
|
max_rotation_x = deg_to_rad(max_rotation_x)
|
2024-02-09 23:10:51 +00:00
|
|
|
|
|
|
|
func _unhandled_input(event):
|
|
|
|
if event.is_action_pressed("look"):
|
|
|
|
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_CAPTURED)
|
2024-02-17 11:14:21 +00:00
|
|
|
enabled = true
|
|
|
|
elif event.is_action_released("look"):
|
2024-02-09 23:10:51 +00:00
|
|
|
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_VISIBLE)
|
2024-02-17 11:14:21 +00:00
|
|
|
enabled = false
|
|
|
|
|
|
|
|
func _input(event):
|
2024-02-09 23:10:51 +00:00
|
|
|
if !enabled:
|
|
|
|
return
|
|
|
|
|
|
|
|
if not event is InputEventMouseMotion:
|
|
|
|
return
|
|
|
|
|
|
|
|
rotation.x += deg_to_rad(-event.relative.y * sensitivity)
|
|
|
|
rotation.y += deg_to_rad(-event.relative.x * sensitivity)
|
2024-02-12 15:58:17 +00:00
|
|
|
|
2024-02-17 11:14:21 +00:00
|
|
|
rotation.x = clampf(rotation.x, min_rotation_x, max_rotation_x)
|