Anri/AdBlockNot
Archived
1
0
Fork 0

Escape to free cursor, click to trap it again

This commit is contained in:
Mylloon 2024-01-27 12:58:26 +01:00
parent 0630ffd7f8
commit 4181a18804
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 18 additions and 2 deletions

File diff suppressed because one or more lines are too long

View file

@ -12,10 +12,14 @@ func _ready():
# Called at each input
func _input(event):
if event is InputEventMouseMotion:
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
# Move the camera axis
rotate_y(-deg_to_rad(event.relative.x * MOUSE_SENSITIVITY))
head.rotate_x(-deg_to_rad(event.relative.y * MOUSE_SENSITIVITY))
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-89), deg_to_rad(89))
if event is InputEventMouseButton and event.button_index == 1:
# Trap the cursor on click
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
@ -24,3 +28,7 @@ func _process(delta):
input.x = Input.get_axis("move_left", "move_right")
input.z = Input.get_axis("move_forward", "move_backward")
apply_central_force(basis * input.normalized() * SPEED * delta)
# Free cursor
if Input.is_action_just_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)