Improved camera
This commit is contained in:
26
client/camera/CameraPivot.gd
Normal file
26
client/camera/CameraPivot.gd
Normal file
@ -0,0 +1,26 @@
|
||||
extends Node3D
|
||||
|
||||
@export var sensitivity: float
|
||||
|
||||
var enabled: bool
|
||||
|
||||
func _ready():
|
||||
assert(rotation_order == EULER_ORDER_YXZ)
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event.is_action_pressed("look"):
|
||||
enabled = true
|
||||
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_CAPTURED)
|
||||
|
||||
if event.is_action_released("look"):
|
||||
enabled = false
|
||||
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_VISIBLE)
|
||||
|
||||
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)
|
Reference in New Issue
Block a user