Finite State Machine Help

Hi, all!

I am coding my game project and it is all going on quite nicely, but before I continue, I’d like to clear things up about finite state machines.

I have a ship with regular controls (shooting, movement, etc). I would consider this the ship’s first state.

Well, when the ship approaches an obstacle, if the player responds to a key prompt, regular control for the ship is deactivated, and an animation plays. I would consider this the ships second state.

When ‘repairing’ itsself, the ship has slower movement speed and is more prone to damage. I would consider this the ship’s third state.

I came from the Blender Game Engine, where a finite state machine was an integral (and easy to implement) part of every game.

I’ve seen little to no documentation from Unity about it, so I’d like to know.

How would I code a simple state machine like this? I mean, this is SIMPLE. Not even close to what enemy AI will have to be, so I have to nip this issue in the bud.

If you have any pointers / links / tuts / words of warning / nuggets of wisdom, I would be glad to receive your knowledge.

Thanks a ton! I’m eager to learn! - YA

To be honest, I always sort of cheated at state machines. I’d create a small enum and switch through that in the update (Mind you, I was never using it for anything large, it was used for playing different sprite animations, so it never slowed anything down).

Though I did find this tutorial, which seems to be pretty explanatory, check it out and see if it helps :slight_smile:

Petey at BergZerg uses FSMs. Here’s a link: