UE4 Daily Study Notes_AI Chapter (2)

Change Npc speed


NewService button to create a service , which is similar to Task, but it does not return a result
and then converts it to NPC. At the same time, create a new variable Speed. After it is made public, you can directly
set the speed of the NPC in the behavior tree.

Placement


 Specific movement speed realization method


 

Npc control behavior mode according to enumeration


Create a Task enumeration variable for switching modes and judgments to increase readability, it is not difficult here

          The complete behavior tree is shown above


 

When the NPC reaches the attack range, it will attack


Key points : SimpleParallel selection mode is FinshMode---Delayed
. When the main task node is completed, wait for the secondary task to trigger. If the secondary task is triggered, it will be executed. If it is
not triggered, it will continue to go down.

If it is set to Immediate , the main task will be run Go straight down, obviously does not meet the requirements

 The behavior tree is shown in the figure


Set the attack distance and determine


NPC auditory perception

method:

1> First modify the AI ​​perception in Npc_AI, add a hearing to it, and open the neutral, friendly, and enemy. You can modify the hearing range on the top

2> Delete the previous perception method and modify it to when the perception is updated

 3> The specific call method NpcPerception, the idea is to call vision, hearing, and two perceptions through a loop.

 4> Add a "sound" event, press F, create a sound, and create a noise event at the same time, give the player's position to the past

 5> Modify the behavior tree like this. When you hear the movement, wait for two seconds and go to have a look. If there is no one in two seconds, continue patrolling

 


Fix AI can't find people BUG

 Change the perception here. The larger the value, the harder it is to run away. After losing the target, find a position 300 distance away from the last successful position. If there is, the target will continue to chase.

Guess you like

Origin blog.csdn.net/qq_35337794/article/details/121645454