I have been working on games for many years now, and I have written things ranging from simple gameplay and AI logic to complex navigation systems, animation graphs and behavior trees!
One of the things that I have struggled with repeatedly over the years is always the same simple problem: managing the behavior of entities over time.
At its heart, the task is very straightforward: I need an entity to perform one or more actions over multiple frames, and to have some smarts about what it is doing in the process. This could be, for instance, a PowerUp that needs to flash every second until the player picks it up, or a Monster that has to react to the player entering a given radius. In short, most of your day-to-day game logic or simple AI.
Game programmers write this kind of code so frequently that we don’t really give the task a second thought. We even have a well established way of approaching the problem: a State Machine.
And the problem isn't with states machines themselves - they are the right tool for the job - the problem is with how we actually write them.
Read the rest of this article on Gamasutra