4 ms·
Not sure I necessarily agree with all these. Its common in game programming to use a form of state machine that defines a character's animation. Characters ca
by jayd16 4y ago
Not sure I necessarily agree with all these. Its common in game programming to use a form of state machine that defines a character's animation. Characters can be in an idle state, an attacking state, a hit-react state. Because its desirable to have the animations blend, the state machines transitions are not atomic.
Now, you could argue that this design is not a state machine but I think its more useful to understand that such a thing that is VERY similar to a state machine but has non-atomic transitions does exist and is commonly used.
- murderfs 4y agoThat just means that the actual state machine has intermediate states for each transition.
- jayd16 4y agoYou can look at it this way but it's much more useful to treat them as conceptually non-atomic.
- layer8 4y agoThink about the following: The transitions from one state to another are triggered by specific events. What happens in the game when such an event occurs during the transition? Unless the event is outright ignored during transitions, the object (character) is in some state which defines how it reacts to that event. Maybe it’s a separate “transitioning” state, or maybe the character is logically already in the target state, even though the transition animation is still playing out. The bottom line is: States are defined by how the system reacts to events. Insofar as the system always reacts to events in some way, it is always in a specific state.
- jayd16 4y agoI really have no idea what you're trying to say here. If a system responds to events it's in a state? Is anything not a state machine by this definition? Anyway, my point was that these are all just conceptual models and another conceptual model that's useful is one with non-atomic transitions.
- layer8 4y agoA state is a (mathematical) function from events to the next state. There is a set of events that can potentially occur, and the function tells you what the next state will be given that event. That’s the mathematical definition of a state machine. You can reverse-engineer what states a system can be in by considering what those possible functions are. For example, consider a state A of some object in your game. For event E (say, the player presses some specific button), the object may transition to state B. For a different event F (say, the object collides with a particular type of other object), it may transition to state C. For yet another event G, the object may remain in state A. Thus the function corresponding to A is { E -> B, F -> C, G -> A } (assuming that E, F, G are the only possible events). Now, you’re saying that the object can be within the transition from (say) A to B. The question is, if one of the possible events occurs during that transition, what does the corresponding function look like? For example, if event F occurs, does the object still continue to go to B, or does it maybe now go to C, or to yet another state? You can write down the corresponding function. If that function is the same as the A function, then that means that the object is actually still in state A. If the function is the B function, then it means the object is actually already in state B. If the function is different from both the A and the B function, then it means the object is actually in a third separate state. Note that an event can also be “the transition animation has finished playing”. The point is, using that functional definition of states (which is the usual definition of state machines or FSAs), for any system with non-atomic transitions there is an equivalent state machine with atomic transitions, and that latter one is what is normally understood to constitute a proper state machine.
- layer8 4y agoOne thing to add: A major benefit of state machines is that you can clearly reason about its behavior. If, however, you have non-atomic state transitions, the behavior during a transition, i.e. how it reacts to events occurring during a transition, is unclear. The reason why state transitions are normally considered to be atomic is so that the system is in a well-defined state at every point in time, so that in turn the behavior of the system is well-defined at every point in time.