[UE4] Use AI behavior tree to realize AI moving to player

1. Create an AIController subclass

2. The AI ​​character uses the AIController subclass just created

3. Create a blackboard and a behavior tree

4. Variables required for blackboard creation

5. Run Behavior Tree

First call the function at the beginning of your own AIController event to select the created behavior tree

6. Add perception components

7. Add sensory configuration

Add sensory configuration, here I use vision configuration, you can adjust the radius and angle of sight.

Remember to check Detect neutral cube, otherwise the protagonist may not be detected.

8. Write event logic

When using object-aware updates

To set the value in the blackboard is to use the function of setting the value to xx, increase the variable in the key name, and change the default value of the variable to the corresponding value: such as IsFind and Target.

Set the blackboard player object and whether to find the bool value

9. Create a MoveToPlayer task:

Obtaining the value is also obtained by using xx as an object. Remember to change the default value of the KeyName variable to Target.

Use the AI ​​Move To function to move towards the player.

Each task must be called to complete the execution at the end, otherwise the task will not end.

10. Writing AI Behavior Trees

Use Selector to judge, if IsFind is true, execute MoveToPlayer, otherwise execute Wait

11. Placing Navigation Volumes

Only in the navigation network body, AI can move.

I have covered a large area here.

Guess you like

Origin blog.csdn.net/Alexander_420/article/details/123080116