Hi everyone,
I'v a little issue on how I should implement a state machine logic in my game.
(as described in http://www.gamedev.net/page/resources/_/technical/game-programming/state-machines-in-games-r2982)
I'm programming a platformer and state machine logic seems fine for it except for one particular case.
Let say I've three states for the player, idle, walk and attack
- idle is the beginning state.
- walk is triggered when pressing a direction and end when this direction is released or when another state is called.
- attack is triggered when attack button is pressed.
All of thes states are neighbors from each other : each of them can transition to one another.
But if I press a direction, then the attack button (without releasing direction), when attack state is expired, the character should transition back to walk.
There's a bunch of solution tha crosses my mind for that but I'm not sure what's the best :
- character has an internal state walking or not triggered by direction down and direction up, which is used to choose the next state after attack. It seems a little clumsy as it is kind of a parallel state machine.
- adding an input event "direction pressed" in addition of "direction down" and "directionup" which is fired in event queue from the moment direction is pressed until it is released, walk event should be now triggered by this event.
or other things I hevn't thought of.
What do you think ?