- Hands-On Artificial Intelligence with Unreal Engine
- Francesco Sapio
- 323字
- 2021-06-24 15:23:30
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;
}
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):

- CockroachDB權(quán)威指南
- Developing Middleware in Java EE 8
- Mastering AndEngine Game Development
- 硅谷Python工程師面試指南:數(shù)據(jù)結(jié)構(gòu)、算法與系統(tǒng)設(shè)計(jì)
- ExtJS高級(jí)程序設(shè)計(jì)
- Python+Tableau數(shù)據(jù)可視化之美
- Python Data Science Cookbook
- R語(yǔ)言:邁向大數(shù)據(jù)之路(加強(qiáng)版)
- SQL Server 2016 從入門(mén)到實(shí)戰(zhàn)(視頻教學(xué)版)
- SpringBoot從零開(kāi)始學(xué)(視頻教學(xué)版)
- Java 9 with JShell
- Mastering Leap Motion
- SCRATCH編程課:我的游戲我做主
- Python深度學(xué)習(xí)與項(xiàng)目實(shí)戰(zhàn)
- Kotlin程序員面試算法寶典