All Questions

Community

V
Vinicius Vinhas

Combined states

Is it possible to have combined states? Let's say I want to have a state for when the character is running and attacking at the same time, since the state machine can only have one state active, is it possible to stack these states in order to react accordingly? The same would happen if he's jumping and dashing, for instance.
  • While you could, you don't want to combine states. The point of the state pattern is to segregate states.

    You can do one of two things:

    • Use a pushdown automata to stack a dash state onto the air state and pop back to air once the character finished dashing. It's a feature of your state machine that, instead of tracking a single state, uses a stack (array) of states.
    • Have an AirDash state that's specific to dashing in the air.