官术网_书友最值得收藏!

Finding uses for FSMs

Although we will primarily focus on using FSMs to implement AI in our game to make it more fun and interesting, it is important to point out that FSMs are widely used throughout game and software design and programming. In fact, the system in Unity 2017 that we'll be using was first introduced in the Mecanim animation system.

We can categorize many things into states in our daily lives. The most effective patterns in programming are those that mimic the simplicity of real-life designs, and FSMs are no different. Take a look around and you'll most likely notice a number of things in one of any number of possible states. For example, is there a light bulb nearby? A light bulb can be in one of two states—on or off (so long as we're not talking about one of those fancy dimming lights). Let's go back to grade school for a moment and think about the time when we were learning about the different states matter can be in. Water, for example, can be solid, liquid, or gas. Just as in the FSM pattern in programming where variables can trigger a state change, water's transition from one state to another is caused by heat:

The three distinct states of water

Though there are no hard rules beyond those of our own implementation in programming design patterns, it is a characteristic of FSMs to be in one, and only one, state at any given time. With that said, transitions allow for a "hand-off", of sorts, between two states, just like ice slowly melts into water. Additionally, an agent can have multiple FSMs, driving any number of behaviors, and states can even contain state machines of their own—think Christopher Nolan's Inception, but with state machines instead of dreams.

There are many different implementations and variants of the FSM in C# and Unity, many of which can be found in the Unity Asset Store, but they share a few key features:

  • They define the various states that an object can be in
  • They provide a mechanism for transitioning from one state to another
  • They provide a way to define the rules that govern transitions

Unity's Mecanim system, though intended originally for driving animations in a state-based manner, fits the bill quite well as it provides a lesser-known, more generic set of FSM features.

主站蜘蛛池模板: 寿光市| 察雅县| 北碚区| 濉溪县| 上杭县| 达拉特旗| 乌海市| 即墨市| 崇礼县| 神农架林区| 马边| 沛县| 敖汉旗| 蒙城县| 海兴县| 泰和县| 神池县| 通山县| 上高县| 双柏县| 乐陵市| 日土县| 临泽县| 故城县| 济南市| 随州市| 米易县| 武威市| 宣化县| 泽州县| 隆化县| 股票| 灵璧县| 吴桥县| 石河子市| 定兴县| 昌乐县| 鄂托克前旗| 泰兴市| 溧阳市| 新和县|