UE's AI Foundation (2) EQS

1. EQS basics

1.1 Generator node

insert image description here

Generator: Generate a series of test points in the range where it needs to be generated for weighted sum testing.

1.1.1 Actors of Class

insert image description here

It is used to find the Actor class within the range, regardless of the terrain, viewing angle, etc., as long as the Actor is in the range class, it will be found.

1.1.2 Points:Grid

Used to generate a grid, there are size and spacing parameters, and you need to specify which object to generate around.

insert image description here

1.2 Scenarios

EnvQueryContext_Item (item) is the small ball seen in the Test Pawn, which is the point generated by the generator.
EnvQueryContext_Querier (querier) is the Pawn occupied by the AI ​​controller, which executes the behavior tree that starts the scene query.

insert image description here

In Actors of Class, if the search center uses EnvQueryContext_Item, players cannot be found, and if the search center uses EnvQueryContext_Quener, players can be found within a certain range.

Custom scenario : use EnvQueryContext_BlueprintBase (EQC) as the environment query scenario, and return the target through the overloaded function in the blueprint.

insert image description here

1.3 Testing

In EQS, tests are used to determine which of the items produced by the generator is the best choice .

1.3.1 Distance test

insert image description here

Note:
(1) Under relative standardization, the smallest is 0 and the largest is 1.
(2) The constants are all 1 under absolute normalization; the closest one is 0 under relative normalization.
(3) Inverting linearity is the reverse of linearity.
(4) The score factor can usually be regarded as a multiplication factor.
(5) Because the score is 0-1, the score will be more inclined to 0 after square, and the score will be more inclined to 1 after square root.

1.3.2 Dot test (dot product test, direction test)

insert image description here

Note:
(1) There are two modes, one is Rotation, that is, the direction of the vector directly, and the other is two points, the direction of the vector from the first point to the end point.
(2) Using the dot product of two vectors is to calculate the score of the angle between the two vector directions, as shown in the figure below, the score in the forward direction is 1, and the score in the backward direction is 0.

insert image description here

1.3.3 Trace test

insert image description here

The Boolean match is true, that is, match the value of true, set the value of true to Trace, and filter it out. As shown below.

insert image description here

1.3.4 Overlay test

insert image description here

1.3.5 Project projection test

The Project projection test is mainly used to correct the position of the test point, such as generated on uneven ground.
There is a Projection Data property in the Grid that can be used to correct the position of the generated point, which is consistent with the role of the Project projection test.

insert image description here

Adding a Project projection test can filter and score according to modifying the properties of Projection Data.

insert image description here

2. Simple application of EQS

2.1 NPC looking for players

Check the EQS option in the project settings.

insert image description here

(1) Create new Player Charater class EQS_NPC, AIController class EQS_AI, blackboard EQS_BB, behavior tree EQS_BT, scene query blueprint class EQ_FindPlayer.

insert image description here

Create a new EnvQueryContext_BlueprintBase blueprint class and name it EQC_PlayerContext.

insert image description here

(2) Overload the Provide Single Actor function in the EQC_PlayerContext blueprint to add the return value of the player object in EQS.

insert image description here

insert image description here

(3) In the EQ_FindPlayer blueprint class, lead out the Point:Grid node and change it to a radius of 1000 and an interval of 150.
Added only filter test Trace .

insert image description here

Add the score-only test Distance and set the integration factor to -1.

insert image description here

(4) Add key frames to the blackboard, IsFindObject of Boolean type, ObjectPosition of vector type, and ObjectActor of object type. Note: the Base Class of ObjectActor is Actor .

insert image description here

(5) Write BTTask for random movement

insert image description here

(6) Add the AIPerception component in the NPC_AI blueprint, and add AI Sight config.

insert image description here

Updated when target awareness was added for AIPerception.

insert image description here

Update the storage Actor when the target is aware and determine whether it is a Player.

insert image description here
insert image description here
When no target is found, set a timer of 5 seconds, and set no target found, lose target after 5 seconds. When the perception is found, it enters the Fight logic.

(7) Write the corresponding behavior tree logic.
The logic of the behavior tree execution process is as follows : First, AI patrols. If it sees the player, it will trigger a visual perception update , and the AI ​​will always look at the player ;

insert image description here

Final effect : After the AI ​​sees the player, it faces the player. If the player dodges, the AI ​​will move to a new position (the result of the EQS query) and continue to look at the player.

2.2 Hiding players

insert image description here

Add a filtered-only test Trace.

insert image description here

Add score-only test Distance.

insert image description here

Then add the score-only test Distance.
Note: EnvQueryContext_Querier searches around the AI ​​character, that is, it returns the Pawn controlled by the AI ​​controller.
The role here is the point that is farthest from the character and closest to the AI ​​itself.

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/qq_45617648/article/details/130938339