playMaker

Author Topic: Get key up/down issues  (Read 554 times)

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Get key up/down issues
« on: March 15, 2021, 11:06:40 PM »
Hello,

I would like to require it that two or more keys be pressed or released at the same time in order for an event to fire. How do I get it where multiple keys are required to either be pressed or let go of. Sorry if this is a simple question. Thanks!

John Bassi

Gustav

  • Junior Playmaker
  • **
  • Posts: 53
Re: Get key up/down issues
« Reply #1 on: March 16, 2021, 09:31:55 AM »
Hi,

I would create an empty GameObject with one FSM, monitoring all inputs as a kind of Input Handler. This FSM catches all input events and sets global Bool Variables. They could be named after the buttons like "buttonA" or "buttonB".

Now use bool actions to test for the values of these Bool Variables in any FSM you like. You can use the Bool All True action to test if more than one bools are true / buttons were pressed.

Depending on the execution order of all the FSMs in your game the detection of the input could be in this case one frame off/later. If that's a problem you could use a global event sent from the Input Handler FSM broadcasted to all FSMs, for example "InputDetected".

A huge advantage of this method is that you can change the inputs in one central place. If you want to use another input system later on, just go to the Input Handler and swap it out.


Regards
Gustav
« Last Edit: March 16, 2021, 09:48:39 AM by Gustav »