extends Node var mouse_movement = Vector2.ZERO func get_mouse_movement(): var ret = mouse_movement mouse_movement -= ret return ret func add_mouse_movement(relative): mouse_movement += relative func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) func _notification(what): if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT: Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) func _input(event): if event.is_action_pressed("ui_cancel"): Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) if Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE: if event.is_action_pressed("click"): Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) else: if event is InputEventMouseMotion: add_mouse_movement(event.relative)