Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lsgrandchamp |
Hi,
I’m working on a prototype for a 2D sidescroller game and I’m having some problems making the player shoot and run at the same time.
The overview is:
- While the player is holding the “Shift” key, the player starts to run. As soon the player releases the “Shift” key, it starts to walk instead. This part is working as intended.
- If the player presses the “KEY_KP_2” (Numberpad 2), it shoots a projectile. This is working as intended in every state but the “Running” state, where the player is also holding the “Shift” key.
I’ve tried the solution described in Godot Documentation, but to no avail.
The code is written as follows:
if event is InputEventKey and event.pressed:
print("pressed: " + String(event.scancode))
if event.scancode == KEY_KP_2:
print("KP_2 pressed")
if event.shift:
print("Shift+KP_2 pressed!")
return true
The outputs:
- When I press the KEY_KP2 key, it prints “16777352”;
- When I press the Shift key, it prints “16777237”;
- When I press the Shift and KEY_KP2 at the same time, it prints “16777234”
As shown, I’m having a hard time to detect the “Shift+NP2” press. Is there a specific scancode for “Shift+KP_2”?
Regards,
Lucas Sene