32 lines
788 B
GDScript
32 lines
788 B
GDScript
extends Camera3D
|
|
|
|
@export var mouse_sensitivity := 0.003
|
|
|
|
var rotation_x: float
|
|
var rotation_y: float
|
|
|
|
|
|
func _ready():
|
|
sync_rotation_from_transform()
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
|
|
func _input(event):
|
|
if event is InputEventMouseMotion:
|
|
rotation_y -= event.relative.x * mouse_sensitivity
|
|
rotation_x -= event.relative.y * mouse_sensitivity
|
|
|
|
rotation_x = clamp(rotation_x, -PI / 2.0, PI / 2.0)
|
|
|
|
rotation.x = rotation_x
|
|
rotation.y = rotation_y
|
|
if event is InputEventKey:
|
|
if event.pressed and event.keycode == KEY_ESCAPE:
|
|
get_tree().quit()
|
|
|
|
|
|
# Вызывать каждый раз после ручной установки global_transform (телепорт/спавн)
|
|
func sync_rotation_from_transform():
|
|
rotation_x = rotation.x
|
|
rotation_y = rotation.y
|