Stabilize camera drag and Tab menu input

This commit is contained in:
Alexander Sellite 2026-08-21 21:33:02 -04:00
parent 86e5980019
commit bb1942a057
4 changed files with 43 additions and 38 deletions

View file

@ -466,11 +466,10 @@ var _catch_attachment_offset: Vector3 = Vector3(0.0, 0.08, 0.04)
var _gravity: float = float(ProjectSettings.get_setting("physics/3d/default_gravity"))
var _camera_dragging: bool = false
var _camera_drag_button_held: bool = false
var _camera_input_enabled: bool = true
var _camera_drag_prior_mouse_mode: Input.MouseMode = Input.MOUSE_MODE_VISIBLE
var _camera_drag_capture_pending: bool = false
var _camera_drag_generation: int = 0
var _camera_drag_pointer_origin: Vector2 = Vector2.ZERO
var _camera_drag_restore_pointer: bool = false
var _free_camera_active: bool = false
var _free_camera_body: CharacterBody3D
var _free_camera: Camera3D
@ -1616,7 +1615,6 @@ func _input(event: InputEvent) -> void:
return
var mouse_button := event as InputEventMouseButton
if mouse_button != null and event.is_action("camera_drag"):
_camera_drag_button_held = mouse_button.pressed
_set_camera_dragging(mouse_button.pressed)
return
var mouse_motion := event as InputEventMouseMotion
@ -1626,7 +1624,6 @@ func _input(event: InputEvent) -> void:
_rotate_free_camera(mouse_motion.screen_relative * mouse_sensitivity)
else:
_rotate_camera(mouse_motion.screen_relative * mouse_sensitivity)
_request_camera_drag_capture()
func _notification(what: int) -> void:
@ -1689,38 +1686,24 @@ func _set_camera_dragging(active: bool) -> void:
if _camera_dragging == active:
return
_camera_dragging = active
_camera_drag_generation += 1
_camera_drag_capture_pending = false
if active:
_camera_drag_prior_mouse_mode = Input.mouse_mode
_camera_drag_restore_pointer = _camera_drag_prior_mouse_mode in [
Input.MOUSE_MODE_VISIBLE,
Input.MOUSE_MODE_CONFINED,
]
if _camera_drag_restore_pointer:
_camera_drag_pointer_origin = get_viewport().get_mouse_position()
# Capture starts with the physical press, before any motion is applied.
# Switching modes after the first movement can synthesize a center warp
# in the middle of the drag and interrupt camera control.
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
else:
_camera_drag_button_held = false
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
Input.mouse_mode = _camera_drag_prior_mouse_mode
func _request_camera_drag_capture() -> void:
if (
_camera_drag_capture_pending
or Input.mouse_mode == Input.MOUSE_MODE_CAPTURED
):
return
_camera_drag_capture_pending = true
_capture_camera_drag_pointer.call_deferred(_camera_drag_generation)
func _capture_camera_drag_pointer(generation: int) -> void:
if generation != _camera_drag_generation:
return
_camera_drag_capture_pending = false
if (
not _camera_dragging
or not local_control_enabled
or not _is_camera_input_enabled()
or not _camera_drag_button_held
):
return
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
if _camera_drag_restore_pointer:
Input.warp_mouse(_camera_drag_pointer_origin)
_camera_drag_restore_pointer = false
func _get_network_aware_speed() -> float: