- 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.
- INSTANT Mock Testing with PowerMock
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- 趣學Python算法100例
- JavaScript從入門到精通(第3版)
- TypeScript實戰指南
- MATLAB定量決策五大類問題
- 程序是怎樣跑起來的(第3版)
- Python數據結構與算法(視頻教學版)
- SQL Server與JSP動態網站開發
- Access 2010數據庫應用技術實驗指導與習題選解(第2版)
- Kubernetes進階實戰
- 區塊鏈項目開發指南
- Appcelerator Titanium:Patterns and Best Practices
- 從“1”開始3D編程
- 程序員面試金典(第6版)