Some actions not registered when multiple keys are pressed at once

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

I have added a custom mapping in the godot project settings called “shoot” and mapped it to the spacebar. I have my spaceship movement working with the arrow keys, and shooting also works, but when I hold down certain combinations of the arrow keys and the space bar, what I would expect to happen is for the spaceship to continue moving in the desired direction, and shoot while it is moving. Instead, it freezes as long as I am holding the spacebar, and when I release the spacebar, it continues to move but does not shoot.

Here is the script for the spaceship. If the script for the bullet is necessary as well, I will be happy to send it.

extends KinematicBody2D


var velocity = Vector2.ZERO
const SPEED = 250

var bullet_scn = preload("res://Bullet.tscn")

func _physics_process(delta):
	var play_on = false

	if Input.is_action_pressed('ui_down'):
		velocity.y += SPEED
		play_on = true
	if Input.is_action_pressed('ui_up'):
		velocity.y -= SPEED
		play_on = true
	if Input.is_action_pressed('ui_right'):
		velocity.x += SPEED
		play_on = true
	if Input.is_action_pressed('ui_left'):
		velocity.x -= SPEED
		play_on = true
	if Input.is_action_just_pressed('shoot'):
		print("Shooting")
		var bullet = bullet_scn.instance()
		# bullet.position = get_global_position()
		get_parent().add_child(bullet)
		get_parent().move_child(bullet, 0)

	if play_on:
		$Sprite.play("on")
	else:
		$Sprite.play("idle")



	move_and_slide(velocity)
	velocity = Vector2.ZERO

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass


func _on_Asteroid_body_entered(body):
	pass
:bust_in_silhouette: Reply From: CreekWorks

I think your problem is that when holding two opposite directions at once they will cancel out, other than that I’m not sure.
Try

if Input.is_action_pressed('ui_down'):
    velocity.y += SPEED
    play_on = true
elif Input.is_action_pressed('ui_up'):
    velocity.y -= SPEED
    play_on = true
if Input.is_action_pressed('ui_right'):
    velocity.x += SPEED
    play_on = true
elif Input.is_action_pressed('ui_left'):

If you are having problems with being able to shoot you want to spawn your bullet on a Position2D that you should put in front of where you want to shoot from

try

if Input.is_action_just_pressed('shoot'):
    print("Shooting")
    var bullet = bullet_scn.instance()
    bullet.position = $Position2D.global_position
    get_parent().add_child(bullet)
    get_parent().move_child(bullet, 0)
:bust_in_silhouette: Reply From: TinsaTech

Apparently it depends on your keyboard how many keys can be pressed at once and which combinations can be pressed at the same time.

You can test this here: https://www.xem.us/rollover/rollover.html

Also, shoutouts to this Reddit - Dive into anything (thats where I found out)

Wow, thanks for this answer and the link to the tester!
I totally did not know that!

(I am on a Mac and only 2 arrow keys are allowed at the same time, on WASD however it’s no problem.)

st_phan | 2022-10-13 18:12