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

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.

主站蜘蛛池模板: 巴马| 开远市| 万山特区| 建瓯市| 丘北县| 秦皇岛市| 枣庄市| 惠州市| 濉溪县| 汤阴县| 县级市| 玉门市| 安新县| 北票市| 汾西县| 伊金霍洛旗| 墨竹工卡县| 房产| 临漳县| 武清区| 达尔| 宁安市| 舞阳县| 苍山县| 灵武市| 呼伦贝尔市| 喀什市| 富源县| 铁力市| 蕲春县| 广灵县| 商水县| 古蔺县| 北安市| 福鼎市| 沁源县| 老河口市| 姜堰市| 招远市| 绥芬河市| 隆德县|