Finite State Machine For Enemies In My FMP

When I initially created the enemies in Secrets Of The Shaolin I had troubles finding a way to navigate between things like searching for the play and attacking.

Through some research I discovered finite state machines which is essentially a behavioral model used when designing software. But in terms of implementing it into my enemies it was going to be used to control what they can do and when.

The first state I created was the Idle state, in which the enemy just does.. nothing. but the other states such as patrolling and chasing are more complex.

I knew I wanted to have the enemies actively patrolling around to kind of give the sense that you were on a stealth mission. so for this I had the enemy follow a gameObject that had an animation that led it around in a loop. In this state if the player object enters a collider attached to the enemy then it will start to run at the player and attack.

In the attack state The enemy cannot move or attack again. I did this because without it the enemy would attack again before it even did any damage so it ended up doing nothing.

Overall I found this worked very well as a base and also allows me to expand to more complicated states very easily later on.


Leave a Reply

Your email address will not be published. Required fields are marked *