- Unity 2017 Game AI Programming(Third Edition)
- Ray Barrera Aung Sithu Kyaw Thet Naing Swe
- 398字
- 2021-07-02 19:14:14
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.
- 零起步玩轉掌控板與Mind+
- Learning Real-time Processing with Spark Streaming
- 深度學習經典案例解析:基于MATLAB
- R語言數據可視化實戰
- Apache Karaf Cookbook
- Mastering Python High Performance
- 算法訓練營:提高篇(全彩版)
- 微信小程序入門指南
- 蘋果的產品設計之道:創建優秀產品、服務和用戶體驗的七個原則
- Solr Cookbook(Third Edition)
- 智能手機故障檢測與維修從入門到精通
- C陷阱與缺陷
- Vue.js光速入門及企業項目開發實戰
- Learning Concurrency in Python
- 虛擬現實:引領未來的人機交互革命