0
\$\begingroup\$

In the below code, is the options I've created whether to use single or multiple states for my character or other entity. Still can't decide which one is better inf using state machines.

public enum CharacterState implements State<Entity> {

    animation // ...
    movement // move_down, move_up ...

}   

public enum AnimationState implements State<Entity>
public enum MovementState implements State<Entity>
\$\endgroup\$
2
\$\begingroup\$

The character should have a single state machine.

Animations should be controlled by the character state so they don't need their own character-specific state machine except as part of a generic animation system.

Status variables (health, ammo, invincibility timer, inventory, etc) are part of deciding which state to transition to but not state machines in themselves.

If there seem to be a need of multiple state machines this usually means the character should be split up into different entities, the AI simplified, or both.

The main reason for this is the K.I.S.S. (keep it stupid simple) principle. Multiple state machines on an entity will too often create unexpected combinations of states, often soft-locking the game in a way that is hard to trace and debug.

If, for example, state machine A has 12 states, state machine B has 5, you have 60 possible combinations that may happen, many of which are probably invalid. Trying to figure out which one of those 59 other possible combined previous states is responsible for entering the current combination becomes a much bigger task.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.