Fixed camera pivot UI interaction

This commit is contained in:
Eduard Urbach 2024-02-17 12:14:21 +01:00
parent 8cd45dc511
commit 8656089aba
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -1,23 +1,25 @@
extends Node3D extends Node3D
@export var sensitivity: float @export var sensitivity: float
@export var max_rotation_x: float = 25.0
@export var min_rotation_x: float = -80.0 @export var min_rotation_x: float = -80.0
@export var max_rotation_x: float = 25.0
var enabled: bool var enabled: bool
func _ready(): func _ready():
assert(rotation_order == EULER_ORDER_YXZ) assert(rotation_order == EULER_ORDER_YXZ)
min_rotation_x = deg_to_rad(min_rotation_x)
max_rotation_x = deg_to_rad(max_rotation_x)
func _unhandled_input(event): func _unhandled_input(event):
if event.is_action_pressed("look"): if event.is_action_pressed("look"):
enabled = true
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_CAPTURED) DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_CAPTURED)
enabled = true
if event.is_action_released("look"): elif event.is_action_released("look"):
enabled = false
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_VISIBLE) DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_VISIBLE)
enabled = false
func _input(event):
if !enabled: if !enabled:
return return
@ -27,4 +29,4 @@ func _unhandled_input(event):
rotation.x += deg_to_rad(-event.relative.y * sensitivity) rotation.x += deg_to_rad(-event.relative.y * sensitivity)
rotation.y += deg_to_rad(-event.relative.x * sensitivity) rotation.y += deg_to_rad(-event.relative.x * sensitivity)
rotation.x = clampf(rotation.x, deg_to_rad(min_rotation_x), deg_to_rad(max_rotation_x)) rotation.x = clampf(rotation.x, min_rotation_x, max_rotation_x)