How can I fix the game screen pausing when using mouse and key at the same time?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mojoyup1528

SO, I am making a helicopter for fun. I can get it to fly via the _integrated_physics because it is a 3d rigidbody[rigid]. I will post my .gd below.

I am using both mouse input for movement and keyboard input for movement.
I do have the mouse inside of _inputs(event). The keys, however are inside physics_forces function.

THE ISSUE: When I move the mouse to control pitch and roll, the game screen pauses/freezes if I am also pressing a key, until the input of the mouse is not recognized and updates, then repeats when I activate mouse input. This may be due to using InputMouseMove.

Though, I have no idea how to change it to make all input recognize and function at the same time.

Here is a link to a video showing the pasuing when moving: https://youtu.be/2gjRXMyX4WE

CODE: heli.gd

    extends RigidBody

export (PackedScene) var gun_HUD


var mouse_sensitivity = 1
var direction = Vector3()
var lift = 0.001
var pitchDown = 0
var pitchUp = 0
var rollLeft = 0
var rollRight = 0
var yawLeft = 0
var yawRight = 0
var movement = Vector3()
var active = false
var heli_zone = false
var value = 0;

func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	get_tree().set_input_as_handled()
func _input(event):
	if active:
		var heli = $"."
		if event is InputEventMouseMotion:
			heli.rotation_degrees.z = clamp(heli.rotation_degrees.z - event.relative.x * mouse_sensitivity / 25, -70, 80)
			heli.rotation_degrees.x = clamp(heli.rotation_degrees.x + event.relative.y * mouse_sensitivity / 25, -70, 80)
		exiting_heli()
	elif !active:
		entering_heli()
		
func entering_heli():
	var heli = $"."
	if Input.is_action_just_pressed("ui_e") && heli_zone == true:
		active = true
		var hidden_plyr = get_parent().get_node("Player")
		hidden_plyr.find_node("CollisionShape").disabled = true
		hidden_plyr.active = false
		#hidden_plyr.hide()
		var newLoc = heli.global_transform.origin
		hidden_plyr.global_transform.origin = newLoc
		$pilotCamera.make_current()
		heli.get_node("pilotCamera/heli_HUD").visible = true
		
#try to keep the helicopter stable
func look_follow(state, current_transform, target_position):
	var heli = $"."
	var cur_dir = heli.global_transform.basis.xform(Vector3(0,0,0))
	var up_dir = Vector3(cur_dir.x, 1, cur_dir.z)
	var target_dir = (target_position - heli.global_transform.origin).normalized()
	var rotation_angle = acos(cur_dir.x) - acos(target_dir.x)

	state.set_angular_velocity(up_dir * (rotation_angle / 5))

func _integrate_forces(state):
	if active:
		var heli = $'.'
		var target_position = heli.get_global_transform().origin
		look_follow(state, get_global_transform(), target_position)
		var hidden_plyr = get_parent().get_node("Player")
		var newLoc = heli.global_transform.origin
		hidden_plyr.global_transform.origin = newLoc
		#Controls
		#lift
		if Input.is_action_pressed("ui_space"):
			if lift < 12:
				lift = lift + 0.1
				#add_force(Vector3(0, lift, 0), global_transform.basis.y)
				var pos = Vector3(0,0,0)
				var force = Vector3(0,lift,0)
				var pos_local = self.transform.basis.xform(pos)
				var force_local = self.transform.basis.xform(force)
				self.add_force(force_local, pos_local)
			if lift > 12:
				lift = 10
				
		
		if Input.is_key_pressed(KEY_Q):
			if yawLeft <= 2:
				yawLeft = yawLeft + 0.1
				#add_force(Vector3(0, -yawLeft, 0), heli.global_transform.basis.y*-10.0)
				add_torque(Vector3( 0, yawLeft*12, 0))
			if yawLeft > 2:
				yawLeft = 1
		elif Input.is_key_pressed(KEY_E):
			if yawRight <= 2:
				yawRight = yawRight + 0.1
				#add_force(Vector3(0, yawRight, 0), heli.global_transform.basis.y*-10.0)
				add_torque(Vector3( 0, -yawRight*12, 0))
			if yawRight > 2:
				yawRight = 1
	elif !active:
		pass

func exiting_heli():
	if active:
		if Input.is_action_just_pressed("ui_x") && heli_zone == false:
			active = false
			var hidden_plyr = get_parent().get_node("Player")
			var heli = $'.'
			hidden_plyr.find_node("CollisionShape").disabled = false
			hidden_plyr.active = true
			hidden_plyr.show()
			var newLoc = heli.global_transform.origin - 2 * heli.global_transform.basis.x
			hidden_plyr.global_transform.origin = newLoc
			heli.get_node("pilotCamera/heli_HUD").visible = false

func _on_detectPlyr_body_entered(body):
	if body.name == "Player":
		heli_zone = true

func _on_detectPlyr_body_exited(body):
	if body.name == "Player":
		heli_zone = false
:bust_in_silhouette: Reply From: Wakatta

IMHO the Input class only serves to confuse when used to capture input. For small projects sure no problem but for you do all your input processing in the_input(event) function.

You can use

if event is InputEventKey:
    if event.scancode == KEY_ENTER: # or any key from @GlobalScope.KeyList
        pass

I suspect your problem arises form desyncs of process and input.

So for future reference follow the OOP guidelines. Use one function to manage one action
Use one class to manage one feature.