Modeling player mechanics with a finite state machine
- by K..
I have three states
standing
walking
jumping
When I press D standing transitions to walking. The velocity will be set to a defined value and the player moves.
When I release D walking transitions back to standing, which sets the velocity back to 0.
When I press W and the state is walking it transitions to jumping, but when the player hits the ground, it goes back to standing.
jumping has a transition land that always leads to standing because a state doesn't know about its previous states.
Since standing sets a velocity of 0 the player stops walking, when he hits the ground.
How do I prevent this?