官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 广河县| 瑞丽市| 新民市| 牙克石市| 江川县| 台北县| 合江县| 长岭县| 望江县| 巩留县| 读书| 赤壁市| 奇台县| 灌南县| 郸城县| 民权县| 宜都市| 永宁县| 客服| 彰化县| 登封市| 蒙城县| 佛坪县| 平南县| 宜丰县| 宁夏| 余干县| 花垣县| 兴仁县| 永寿县| 北碚区| 保定市| 陈巴尔虎旗| 苏尼特左旗| 安岳县| 福鼎市| 夏河县| 原平市| 麻江县| 思南县| 定西市|