- 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.
- 演進式架構(原書第2版)
- Django+Vue.js商城項目實戰
- DevOps Automation Cookbook
- C#程序設計教程
- Hadoop+Spark大數據分析實戰
- 云計算通俗講義(第3版)
- SharePoint Development with the SharePoint Framework
- Scientific Computing with Scala
- Windows Phone 7.5:Building Location-aware Applications
- Mastering Unity 2D Game Development(Second Edition)
- Instant Debian:Build a Web Server
- Mastering OAuth 2.0
- 數據結構:Python語言描述
- DevOps 精要:業務視角
- PHP Microservices