I have a simple finite state machine with platforming behavior set up, which works fine. I’m trying to implement gamepad support, where the player could also use keyboard controls at any time.
If you look at the event sheet, it’s obvious what the conflict is: the moment there’s a left or right input, and player_walk_left or player_walk_right is called, it is kicked back to player_idle in the next frame, because either the keyboard key or the gamepad button is released (depending on whether the player is using the keyboard or gamepad), so there’s always a condition to return to the idle state.
What are some good methods for avoiding this kind of conflict, how would you deal with it? Thanks all for looking!
The OR condition might help you.
You can see how I did this in the FSM used in the not a vania example, available in the engine.
As Bouh mentioned, you will need to use the Or condition.
Thank you both for the advice, also, great job on Not-A-Vania, really good, thorough explanations in the comments.
What I’m thinking after looking at this for a while, I need a variable(s) which stores where the last input came from (keyboard or controller).
Then, place the was-released/not-pressed conditions in sub events, so playerState only changes to idle when the value of that variable is valid for that device/input.
Does it sound like I’m on the right track? Thanks again.
i think that’s maybe too complicated? why does it matter if the user presses button on keyboard or gamepad last?
i think just place an or condition with left key pressed and left button of gamepad 1 pressed, et al for the other inputs, and another or condition with the same but inverted.
I agree with MinusDungeonGames. “Or” condition is the solution here rather than trying to separate out the controls entirely. That’s how Not-A-Vania is set up, too.
Thank you all for the advice, I’ve got it figured out
One more question before we label this one solved:
I was wondering about the benefits of creating a function for each state, instead of an external event for each state.
What would be the pros and cons of both approaches?