playMaker

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

hoyoyo80

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Detect multiple keys?
« on: April 18, 2018, 09:54:03 PM »
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

krmko

  • Hero Member
  • *****
  • Posts: 611
    • View Profile
    • Fat Pug Studio
Re: Detect multiple keys?
« Reply #1 on: April 19, 2018, 01: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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12838
  • Official Playmaker Support
    • View Profile
Re: Detect multiple keys?
« Reply #2 on: April 19, 2018, 01: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

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Re: Detect multiple keys?
« Reply #3 on: April 20, 2018, 04: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: 12838
  • Official Playmaker Support
    • View Profile
Re: Detect multiple keys?
« Reply #4 on: Today at 10:47:32 PM »
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