Skip to main content

Finishing up the State Machine

For the past few weeks several of our programmers have been working on pieces of the state machine for the ant's AI. When we tried to pull the various scripts together we ran into some problems with them. Mitch, Connery, and I spent much of this week fixing them as a result.

One of the issues when looking at the state machine scripts was that many of them were not written particularly cleanly and there was quite a bit of bad practice going on in regards to where certain objects were being referenced and found, as well as certain code being looped and repeated unnecessarily. One of the biggest things we did to fix this was ensuring the state machine as a whole retrieved any necessary objects one time then provided those references to the various states as necessary.

There were a lot of issues with the transitions between states as well. There were quite a few times when an ant would just cycle between two states every other frame, which resulted in some rather odd behavior. This was likely due to the states being written separately by different programmers and took a bit of work to clean up. After cleaning up the various states, the AI for the ant worked quite well and allowed us to easily tweak values as Mitch tested. As a result of our work this week the ants are finally moving around in game as expected and look really great when seeing a huge line of them march around. One thing we will need to look into next week is the object pooler that spawns the ants as there have been a few issues with it that popped up.

State machine and its parameters in the inspector

Comments