Monday, 15 October 2012

Finite State Machines


I read AI for Game Development, the chapter on finite state machines (a book in the recommended reading list). In which it explains a simple model for a state machine depicting the ghosts from Pac-Man. I decided to update the example using a situation common to a more modern game. Imagine a guard patrolling a camp. His behaviour can be depicted using this same FSM model. 



There are 3 states and 8 transitions. When all the guards in the camp have this kind of behaviour it can appear quite complex and give the illusion of intelligence. If we assume the patrol state is the default state which will continue while there are no enemies, when a new enemy is seen it will switch to the attack state and remain there while the enemy is close by. Once he has lost too much health he will then call for back up by switch to the final state. If his health has regenerated enough or he has been healed etc,  he will then switch back to the attack state and continue the battle. Once all enemies are disposed of the guard will return to the default state to patrol his camp.

No comments:

Post a Comment