Search the Blog

Monday, September 22, 2014

Which State would a State be in if a State could State it's current State?


We know how our characters move throughout an environment. We also know how they attempt to move through the said environment. We also know how if an entity is in a certain state they will preform according to that state. Or at least we will, after this post!

Many games used what are called finite state machines (abbreviated as FSM) to determine basic behavior patterns for characters with limited AI. Depending on what state-of-being an entity is in, it might have special properties or abilities. It may run faster, blend in with its environment, or forsake other needs that the entity would normally have entirely until it leaves that associated state. As per usual a picture is in order to help describe this setup.

Learn the secrets of the Ninja!

A typical autonomous entity will follow a set of loose commands and priorities based on its state. Our example character's default state would be its wander state (notice the use of Steering behaviors!) Until something causes it to leave this state, our character will simple wander around the screen or area that it is spawned in. A player controlled character getting close (or perhaps within vision) causes our entity to leave the wander state and enter the attack state: With this, it gains a new objective to pursue and attack the player character. From this state, there are 2 possible outcomes: the AI character would either go back to wandering (should it lose sight of the player or if the player flees) or it could enter an evading state (to avoid being hit by the player).


State Machines can be very specific!

State machines are great tools to help with any event-driven scenarios that might change a character's goal or objective. If A happens, then react with B. Another positive to state machines is that they can be set up in such a way as to always be in a state indefinitely (and thus, doing something) until it reaches an end state (usually lose of health or despawning). State machines can also act on more conditions than can be used in basic decision making, which typically involve binary options. Instead of deciding whether to attack the player or not, our FSM could attack the player in different ways depending on its state.




No comments:

Post a Comment