playMaker

Author Topic: Detect Key Combo [SOLVED]  (Read 3653 times)

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Detect Key Combo [SOLVED]
« on: October 16, 2014, 06:21:20 PM »
Hi, im after detecting when 2 keys are pressed at the same time (or near as)
(up arrow + space bar)

what would be the best way to do this?

i need it close to exact as the keys pressed also have other actions when pressed individually
« Last Edit: October 17, 2014, 09:52:57 PM by Lane »

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 713
    • Flashing Lights
Re: Detect Key Combo
« Reply #1 on: October 17, 2014, 03:52:00 AM »
Hi, you can check if a key is already pressed with GetKey or GetButton actions, store them in bools and compare to check what to do next.

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Detect Key Combo
« Reply #2 on: October 17, 2014, 06:26:41 AM »
Hi, i sort of understand what you mean,

I have my keys pressed already stored as bools.
1. Up arrow
2. Space Key

These two do action already based on these bools (ive got a FSM for managing this)

So im guessing i need to go to the 2 places these bools are being used and add in the check additional key pressed before doing the action?

e.g.
1. user pressed up arrow
2. go to new state and check space key
3. Do action

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Detect Key Combo
« Reply #3 on: October 17, 2014, 10:22:57 AM »
I would first try to make a big fsm for managing all of the key press combinations.

You could do it where everything starts in the first state, then divides off for each of the possible keys you could press for moves (i assume four keys? punch/punch/kick/kick). After you branch to one of those other four states I would have a wait action that goes back to the first state if they take too long to press it and have the key down action to go to a different state.

But that could make everything happen ultra fast if you press them in sequence super quickly, so you might need to do the bool option and have a separate compare to see if enough of a delay has elapsed to actually go to the next state.

Overall, it seems like it might be pretty complex when you get enough moves. I would consider making a custom action that condenses the whole wait/compare process down so that its easier to build the FSM. This would require coding, but its probably worth it to avoid building a solution and then taking a really long time to revise anything.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 713
    • Flashing Lights
Re: Detect Key Combo
« Reply #4 on: October 17, 2014, 11:24:33 AM »

e.g.
1. user pressed up arrow
2. go to new state and check space key
3. Do action

I think something like this with Wait on the part 2 like Lane suggested

or if you already use these buttons in other FSMs,
make an empty gameObj who takes all needed bools
(GetFSM bool) + check All True = do a combo action.


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Detect Key Combo
« Reply #5 on: October 17, 2014, 01:30:00 PM »
i would make a fsm for both keys ( in key set key you want, i forgot to set 1 in picture  ::) )

upload image online
then make another fsm checking the bools :


photo hosting sites

i don't know if this is the best way and have not tested it....but i think it should work

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Detect Key Combo
« Reply #6 on: October 17, 2014, 05:04:28 PM »
thanks 'djaydino' and 'lane'

i understood and created my own FSM as a manager like you said Lane and added wait times alongside bools. This worked great!

i did the following
1. Set all bools and wait for movement
2. detect both keys and fire one of them
3. check the other key as been pressed
4. bool check
5. Fire event

i also setup the alternative action from state 3-5 when key was pressed in different order.


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Detect Key Combo
« Reply #7 on: October 17, 2014, 09:50:22 PM »
that's the beauty of Playmaker you can easy try things out and change stuff without having to code everything manually it just saves soo much time.
anyway i'm happy you got it to work :D

can you add [SOLVED] on your subject title pls :)

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Detect Key Combo [SOLVED]
« Reply #8 on: October 18, 2014, 04:33:13 AM »
I tried but someone beat me to it