playMaker

Author Topic: Shared inputs on different FSM  (Read 2046 times)

G-Kaiser

  • Playmaker Newbie
  • *
  • Posts: 34
Shared inputs on different FSM
« on: November 09, 2014, 10:52:04 PM »
Hello,

I am working on a fighting game. I have one FSM that handles crouching and another that handles a fireball motion. Both FSM use the same key. This causes some confusion because in the fire ball motion the down key is used and the down key is used in the fireball motion, but the fireball motion also uses the right key as well. I just need to know how to set up an FSM that will read whether or not the player is going for a crouch or a fireball? I may not have explained myself well here if not, please let me know.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Shared inputs on different FSM
« Reply #1 on: November 11, 2014, 01:23:46 AM »
Hi,

 you'll have to implement a higher level manager for your current "state". but I sense you will byte your own tail with this...

 typically to solve this, I would experiment with the following, I did it on a previous project but it was not as time sensitive as input decision.

maintain an fsm called "Player State" which has as may states as there are player movements, so you would have "Crouching" and you would have "FireBall" as well as the start state.

 have a global event for each of these states "PLAYER / STATE / ENTER CROUCH"
"PLAYER / STATE / ENTER FIREBALL" and when an fsm catches a user input it sends this event as early as possible for other fsm to query for the current state of that "Player State".

Then if your fireball must not be working if the player is crouching, when the fireball fsm catches a user input it will first query for the state and it if founds that it is "Crouching" then it won't validate the input and bail, else it proceed AND fire the global event "PLAYER / STATE / ENTER FIREBALL".

 but again, be carefully you could be end up in a racing condition. I would analyse further what is the logic behind the choice for the same user input to crouch or launch a fireball, the answer may be that there should a higher level context for a player to allow certain types of movement and combos or not so your "Player State" fsm may end up being more generic, with states like "Attacking", "Defencing", "Stealth mode", etc, and then obviously you may not want to launch the fireball if the player is currently in "Stealth mode", that will be up to your game description to decide on these rules of course.

to query for the sucrrent state you can use the action "GetFsmState".

 you can also completly revert this logic, and in the fireball and crouching fsm implement the global events "PLAYER / STATE / ENTER XXX" and based on these switch to a state that doesn't listen to user input ( like disabled in a way) or not. so you would maintain also global events like "PLAYER / STATE / EXIT XXX".

the later approch also means that if you have npc, they can act in a very intuitive way to your player actions, defencing when the player attacks, attack when the player idle etc etc.

Bye,

 Jean

and

Mornar

  • Playmaker Newbie
  • *
  • Posts: 40
Re: Shared inputs on different FSM
« Reply #2 on: November 11, 2014, 06:10:32 AM »
Hi

I have a quite similar problem and i think it would help. I will try this tomorrow.

I have a FSM wich controls my character with mouse drag and another FSM which controls it with MousePick. Both with left mousebutton.
I think i need something like a test if the mouse button is pressed once or held right?

So you say i need an FSM which controls that.
Lets say...if mouse clicked once oder twice then enable mousepick and disable mousedrag. And if mouse is held down then enable mousedrag and disable mousepick? Something like this?

If you had an idea how i can check this just let me no ... it would be really helpful.

Greez
Mornar

G-Kaiser

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Shared inputs on different FSM
« Reply #3 on: December 08, 2014, 12:42:52 AM »
Jean,

I have been trying to implement the instructions you gave but, I am having a bit of trouble. I am not sure if I need to place any actions in the states that are in the "player state" FSM? If so what actions do you suggest? I have been reading the post again and again and I don't quite understand. Can you elaborate any?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Shared inputs on different FSM
« Reply #4 on: May 06, 2015, 06:07:11 AM »
Hi,

 Going trhough my back log, sorry for the delay. Don't hesitate to bump!

 Please find a simple scene, showing how to operate "modes" like your crouching and fireball.

 It's very simple, but requires a clear overview, so hopefully this will demonstrate what you need.

press the up arrow to enter "fireball" mode, and press down arrow to enter "Crouching". Notice that once you have entered a mode, pressing the other key won't let you enter that other mode, because the fsms are aware of the various modes states and so the only scan for the inputs when they are allowed.

It's also using global event, so any fsm can be made aware of what mode is entered or exited, which means for a particular mode, the whole project can behave differently, not just one fsm.

 If you have questions, let me know.

Bye,

 Jean