Reputation: 21
Tried two keys in input map but run code even single key is pressed
if event.is_action_pressed("ui_up") && event.is_action_pressed("ui_left"): //doesn't work
if event.is_action_pressed("ui_up"): //worked
Upvotes: 0
Views: 2508
Reputation: 40315
You are going to get a call to _input
per input event. And the event
object you get as parameter in _input
represents that single input.
So, as Hola correctly explained in comments, you are not going to get an event
object that reports both actions being pressed, because those actions are set to different keys and would be sent as individual events.
If you only care if the input is presser or not, you can query Input
, for example:
if Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_left"):
pass
And that does not have to be in _input
. In fact, I would argue against using _input
unless you really need to. You can do that check in _process
or _physics_process
instead.
Now, something tells me that you don't only want to know if they were pressed, you also will want to know if they were pressed "at the same time" (for some definition of "at the same time").
Again, the easier way to do it is simply checking Input
:
if Input.is_action_just_pressed("ui_up") and Input.is_action_just_pressed("ui_left"):
pass
And I need to tell you that is_action_just_pressed
is not intended to work - and may cause unintended results - if used in _input
. For an explanation of that see Godot - Input.is_action_just_pressed() runs twice.
And if you need more control over what "at the same time" means, or you are going to do it in _input
anyway, I'm going to remit you to an older answer on the sister site for game development: How to make two keys pressed to make an action?
Upvotes: 1