- 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.
- C++ Primer習題集(第5版)
- Expert C++
- 前端跨界開發(fā)指南:JavaScript工具庫原理解析與實戰(zhàn)
- Mastering Entity Framework
- MariaDB High Performance
- 新編Premiere Pro CC從入門到精通
- Spring+Spring MVC+MyBatis整合開發(fā)實戰(zhàn)
- Arduino家居安全系統(tǒng)構(gòu)建實戰(zhàn)
- Terraform:多云、混合云環(huán)境下實現(xiàn)基礎(chǔ)設(shè)施即代碼(第2版)
- Unity 2018 Shaders and Effects Cookbook
- Learning YARN
- 計算機應(yīng)用技能實訓(xùn)教程
- Java EE 7 with GlassFish 4 Application Server
- 30天學通C#項目案例開發(fā)
- Visual Basic語言程序設(shè)計基礎(chǔ)(第3版)