UE4 AI behavior tree notes ()

1. Create a BehaviorTree1 (behaviorTree), a blackboard4 (blackboard), and an ai_controller (AIController).

 2. Create a Boolean variable is see player in the blackboard. Click the left button in the blank space of behaviorTree1 to bind blackboard4. Run behaviorTree in ai_controller

 

 

 This completes the binding between these three. The relationship between them and AI, the four is that when the value in the blackboard changes, behaviorTree uses AIController to let AI take the corresponding behavior according to the changed value.

3. Copy a character and name it AI_bp, delete all blueprints, variables, and cameras in it, and create a spherical collision. Click class defaults to bind to the created ai_controller.

 4. Create a selector under root in behaviorTree1, create two sequences under the selector, right-click sequence, select add decorator, and select blackboard. Left-click the blackboard in the sequence and change the blackboard key to is see player.

 The former key query is is set, and the latter key query is is not set. is set indicates that the Boolean value is see player is true, and is not set indicates that the Boolean value is see player is false.

5. When is see player is false, we want the AI ​​to keep moving randomly. Click new task in behaviorTree1 to create the task find_loc.

 

 clearfocus is to clear the AI's perspective lock, AI moveTo is the movement of the AI, and getRandomReachablePointInRadius is to randomly find a point within the radius. Be sure to add finish execute, otherwise this task will always be executed. I added a wait to let the AI ​​pause after arriving at the location.

 In the same way, we write a task that when the AI ​​finds a player, it is close to the player.

 6. Add an AIPerception component to ai_controller and set senses config. AI Sight config is the perspective of AI. Click below to create an event.

 

 The Boolean value in the blackboard is changed based on whether the player is seen or not. The key name in set value as bool is the value name to be set, and make literal name is to pass in the input.

Guess you like

Origin blog.csdn.net/m0_72249574/article/details/128567802