- Practical Game AI Programming
- Micael DaGra?a
- 381字
- 2021-07-02 20:43:04
Creating a possibility map (FPS)
We'll learn how to create an awareness behavior for the AI character later, so for now we will just be using simple Boolean variables to determine if the player is near our position and what direction it is facing. Taking that into consideration, let's break our image into trigger zones to define when our enemy AI should react.

The YES zones represents the area that triggers our AI to change its behavior from the passive to offensive state. The NO zones represent the area that doesn't have an impact on our AI behavior. I've divided the YES zones into three because we want our AI character to react differently according to the player's position. If the player comes from the right side (YES R), the enemy has a wall that can be used for cover; if it comes from the left side (YES L), we can't use that wall anymore, and once the player is in the middle (YES M), the AI can only move backwards inside of the building.
Let's prepare our script for the enemy AI. In this example, we will use the C# language, but you can adapt the script to any programming language that you prefer, as the principles remains the same. The variables that we'll be using for now are Health, statePassive, stateAggressive, and stateDefensive:
public class Enemy : MonoBehaviour {
private int Health = 100;
private bool statePassive;
private bool stateAggressive;
private bool stateDefensive;
// Use this for initialisation
void Start () {
}
// Update is called once per frame
void Update () {
}
}
Now that we know the basic information required for the AI, we need to think about when those states will be used and how the AI will choose between the three available options. For this, we'll use a possibility map. We already know the areas that trigger our character, and we have already chosen the three behavior states, so it's time to plan the transitions and reactions according to the player's position and behavior.

Our enemy AI can go from PASSIVE to DEFENSIVE or AGGRESSIVE, from AGGRESSIVE to DEFENSIVE, and from DEFENSIVE to AGGRESSIVE, but once our AI knows that the player is around, it will never go back to the passive behavior.
- Learn Type:Driven Development
- 算法訓練營:入門篇(全彩版)
- Learning Linux Binary Analysis
- C/C++常用算法手冊(第3版)
- Hands-On RESTful Web Services with Go
- Go并發編程實戰
- Getting Started with Greenplum for Big Data Analytics
- 大數據分析與應用實戰:統計機器學習之數據導向編程
- Scala for Machine Learning(Second Edition)
- Python 3 數據分析與機器學習實戰
- 從程序員角度學習數據庫技術(藍橋杯軟件大賽培訓教材-Java方向)
- Node.js從入門到精通
- Application Development with Parse using iOS SDK
- Mastering Concurrency in Python
- Qt 4開發實踐