fix: camera forces release of gui focus when moved

This commit is contained in:
Sara Gerretsen 2026-01-07 17:50:29 +01:00
parent 09a82265a6
commit 33da5f1772

View file

@ -63,26 +63,32 @@ func _ready():
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton and (event as InputEventMouseButton).button_index == MOUSE_BUTTON_RIGHT:
get_viewport().set_input_as_handled()
get_viewport().gui_release_focus()
rotating = event.is_pressed()
elif event is InputEventMouseButton and (event as InputEventMouseButton).button_index == MOUSE_BUTTON_MIDDLE:
get_viewport().set_input_as_handled()
get_viewport().gui_release_focus()
panning = event.is_pressed()
elif event is InputEventMouseMotion and rotating:
get_viewport().set_input_as_handled()
get_viewport().gui_release_focus()
var motion := event as InputEventMouseMotion
global_position += (global_basis.y * motion.screen_relative.y - global_basis.x * motion.screen_relative.x) * rotate_speed * distance
look_at(pivot)
global_position = (global_position - pivot).normalized() * distance + pivot
elif event is InputEventMouseButton and (event as InputEventMouseButton).button_index == MOUSE_BUTTON_WHEEL_UP:
get_viewport().set_input_as_handled()
get_viewport().gui_release_focus()
distance = max(1., distance - zoom_speed)
global_position = (global_position - pivot).normalized() * distance + pivot
elif event is InputEventMouseButton and (event as InputEventMouseButton).button_index == MOUSE_BUTTON_WHEEL_DOWN:
get_viewport().set_input_as_handled()
get_viewport().gui_release_focus()
distance = min(1000., distance + zoom_speed)
global_position = (global_position - pivot).normalized() * distance + pivot
elif event is InputEventMouseMotion and panning:
get_viewport().set_input_as_handled()
get_viewport().gui_release_focus()
var backward := Vector3(global_basis.z.x, 0.0, global_basis.z.z).normalized()
var right := Vector3(global_basis.x.x, 0.0, global_basis.x.z).normalized()
var motion := event as InputEventMouseMotion