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

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.

主站蜘蛛池模板: 凭祥市| 望奎县| 襄城县| 甘德县| 宁夏| 舟山市| 阳泉市| 阿城市| 肥西县| 安阳市| 宣城市| 江陵县| 白城市| 讷河市| 峨边| 花莲市| 黎城县| 隆子县| 信阳市| 昂仁县| 荆门市| 哈巴河县| 同心县| 齐齐哈尔市| 沙河市| 班戈县| 嘉兴市| 灵武市| 阜阳市| 耿马| 津市市| 洛川县| 长治县| 柘荣县| 天水市| 英德市| 湾仔区| 宽甸| 泊头市| 彰化市| 康平县|