playMaker

Author Topic: Detect multiple keys?  (Read 2703 times)

hoyoyo80

  • Full Member
  • ***
  • Posts: 136
Detect multiple keys?
« on: April 19, 2018, 12:54:03 AM »
Hi to all can some give me an example on how to combine multiple input to trigger state.

Example, Rolling with Axis Input, Jumping with Axis Input or Any Two button beside axis

Thanks

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Detect multiple keys?
« Reply #1 on: April 19, 2018, 04:11:42 AM »
I don't think it's possible to do it in one frame, try separating it in two fsm's and see if it works out for you.

FSM 1:

State 1: get key a, go to state 2
State 2: get key b, go to state 3

FSM 2:


State 1: get key b, go to state 2
State 2: get key a, go to state 3

Since it's basically impossible to press two keys at the same time, two fsm's will make sure the combo is detected regardless of which key you pressed first.

or you can try it out in one fsm too

state 1: get a, if pressed go to state 2, get b, if pressed go to state 3
state 2: check if b pressed, if it is go to state 4
state 3: check if a pressed, if it is go to state 5
Available for Playmaker work

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Detect multiple keys?
« Reply #2 on: April 19, 2018, 04:18:50 AM »
Hi,

 yes, it's important to understand that an fsm can only be in one active state at a time, so if you are using several input for the same outcome, it will be easier to have distinct fsm listening to each input individually, firing a common set of event to another fsm that doesn't know about the inputs but simply listen to these events.

 Bye,

 Jean

hoyoyo80

  • Full Member
  • ***
  • Posts: 136
Re: Detect multiple keys?
« Reply #3 on: April 20, 2018, 07:13:00 AM »
Hi..thanks for the reply. The two FSM make me wonder on how its works.  If the FSM can be at one state at a time, if using two fsms the structure should be identical? Any tutorial on this.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Detect multiple keys?
« Reply #4 on: April 24, 2018, 01:47:32 AM »
Hi,

I don't think there is a dedicated tutorial on this, but plenty of examples to check it out for sure.

For example check out the 2d platformer sample and how input is separated in multiple fsm.

https://github.com/jeanfabre/PlayMaker--UnityLearn--2dPlatformer

Bye,

 Jean