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

Creating a NavArea class in C++

It's easy to create a NavArea class in C++ as well. First of all, you need to create a new C++ class that inherits from the NavArea class, as shown in the following screenshot:

By convention, the name should start with "NavArea_". Therefore, you can rename it NavArea_Desert (just to vary which kind of terrain the AI can face, since we created a Jungle previously) and place it in "Chapter3/Navigation":

Once you have created the class, you just need to assign the parameters in the constructor. For your convenience, here is the class definition in which we declare a simple constructor:

#include "CoreMinimal.h"
#include "NavAreas/NavArea.h"
#include "NavArea_Desert.generated.h"

/**
*
*/
UCLASS()
class UNREALAIBOOK_API UNavArea_Desert : public UNavArea
{
GENERATED_BODY()

UNavArea_Desert();

};

Then, in the implementation of the constructor, we can assign the different parameters. For instance, we can have a high cost for entering and a higher cost for traversing (with respect to the Default or the Jungle). Furthermore, we can set the color to Yellow so that we remember that it is a desert area:

#include "NavArea_Desert.h"

UNavArea_Desert::UNavArea_Desert()
{
DefaultCost = 1.5f;
FixedAreaEnteringCost = 3.f;
DrawColor = FColor::Yellow;
}
You can always play with these values to see which one works best for you. For instance, you can create an area with a very high entering cost, but a low traversal cost. As a result, you will have an area that, should be avoided if it's only going to be traversed for a little while, but if the agent traverses it for a long period of time, it might be more convenient than the shorter route.

Once you have created the class, you can set it as part of the Nav Modifier Volume, as shown in the following screenshot: 

As a result, you will be able to see your custom area in the Nav Mesh (in this case, with a Yellow Color):

主站蜘蛛池模板: 乐昌市| 乐清市| 灌南县| 玛沁县| 淮南市| 昭觉县| 阿拉善盟| 凉城县| 济源市| 茂名市| 延川县| 额敏县| 民勤县| 莎车县| 临夏县| 静宁县| 铜川市| 元阳县| 铜川市| 凭祥市| 天柱县| 泽库县| 宣化县| 延庆县| 武胜县| 大新县| 竹北市| 尼勒克县| 长寿区| 静安区| 凤山市| 个旧市| 宝鸡市| 铁力市| 阿鲁科尔沁旗| 扬中市| 阳西县| 醴陵市| 城步| 邹平县| 崇州市|