Can i create an action when 2 keys / buttons are pressed at the same time?

Hello, i have action attack that makes the character punch forward and i have the up action (not an axis) that makes the character jump. I want to implement a up punch if the attack action and jump action are pressed at exactly the same time together, is there a way to do this? Thanks

The easiest way is to set a bool for each pressed an call a event or a function that checks to see if both isPressed Bools are true.

Something like this?

Event Action Pressed:

ActionPressed = true;

Event Action Released: (is it necessary if i always set the flag to false on the end of every tick?)

ActionPressed = false;

Event Jump Pressed:

JumpPressed = true;

Event Jump Released: (is it necessary if i always set the flag to false on the end of every tick?)

JumpPressed = false;

Event Tick:

If(ActionPressed && !JumpPressed)
    Normal Attack
else if(ActionPressed && JumpPressed)
    Up Attack
else if(!Action Pressed && JumpPressed)
    Jump
else Do Nothing

ActionPressed = false;
JumpPressed = false;

Like this

And on that Check Condition function you do something like the code i put on Event Tick above right? The problem with that code is that i can have attack pressed without releasing and 1 second later press jump and it still works because both flags are true. I want to detect both at the same time in a split second with very little difference between both presses.

Correct you down want to constantly check this with the tick as it could slow down your detection.

To solve the timing problem i could have a LastPressedActionTime and LastPressedJumpTime and check if the difference is less than a specific value. Can you see another way of doing this?

Why not use an AND bool branch?

I might be mistaken, but just checking Detect 1 && Detect 2 allows the possibility i mentioned above: you press action and don’t let go (Detect 1 is now true) you wait for example 1 second a press Jump (Detect 2 is now true), since Detect 1 == true AND Detect 2 == true the code will run, and i don’t want that to happen, i want the up attack to work only if the difference in time between the presses is between a very short time period, say 50 ms.

Ah i see I was going by your c++ breakdown. then yes that should work.

If we can’t make an action composed by two keys/buttons I don’t see another way. I will try it out and i will let you know :slight_smile: