Three stages of AI
The processing process of AI can be divided into three stages: perception, thinking, and action
perception
- Make a record of the current state of the AI.
- "Basic filtering" is also an act of perception.
- Basic filtering - some information is ignored if other senses have higher priority
think
AI uses the information collected in the perception stage to evaluate the current information and goals, and point out the direction for subsequent actions.
action
- According to the information in the perception stage and the decision-making in the thinking stage, AI will act on the information in the action stage.
- After the action phase is over, the AI will go back to the perception phase again.
- There are visible behaviors, such as jumping and running; there are also invisible behaviors, such as communication
navmesh
create
The shortcut key P can toggle whether the navigation grid is displayed
Introduction to NavMeshes
AI's movement range, there is a navigation mesh bounding volume in the volume in placement mode, pull him into the scene to form a wireframe, and scale it to form the AI movement range
Navigation mesh is divided into static and dynamic
- Static: Calculated before the game runs, the area of the navigation grid
- Dynamic: When the game is running, the area of the navigation grid is calculated in real time
Static and dynamic settings of the navigation grid: Settings in the level editor - project settings - navigation mesh - runtime - runtime generation (default static), and the dynamic method is calculated in real time, which is more in line with intelligent adjustment ;
Use RecastNavMesh to adjust some properties of the navmesh
The Recast Nav Mesh is automatically created when the Nav Mesh is created.
Select RecastNavMesh and adjust it in the details panel.
- Paint Offset - Raises or lowers the nav mesh. Does not change the actual position of the mesh, just the visual effect. (Helpful for displaying occluded areas)
Defaults to 10.
Nav Modifer Volume - No geometry is generated.
NavMesh Barriers - Indicates that an area is difficult to navigate. AI will not prioritize this path. The Nav Mesh is not removed.
NavArea_Null - Removes the NavMesh, cannot pass through.
NavArea_LowHeight - Used where height is insufficient. Can't pass.
NavArea_Default - Can be passed.
Create AIController
Bind the character to the controller
Get variables in blackboard
Get Blackboard: Get the blackboard
Set Value as... (... is the type of value): Get the variable value in the blackboard by assigning a value
Make Literal Name: Assign a value to that value (the variable name in value)
effect
Run Behavior Tree
Run Behavior Tree: Run Behavior Tree (BTAsset: which behavior tree to run)
Behavior Trees (for use with Blackboard)
Control and display the AI's decision-making process
create
The behavior tree should be used together with the blackboard and bound to the blackboard.
behavior tree structure
- Behavior tree: is a method to visualize the decision-making model of AI in the scene.
- Observing the visual structure of the behavior tree, you can clearly understand the execution method and execution order of the behavior tree, without having to understand the specific working method of each node.
- Order of Execution - Determined by the position of each node in the Behavior Tree. From top to bottom, left to right.
- The tree ends with tasks.
synthesis
Synthesis is the root of the AI execution branch. Does not execute like a leaf node, but creates a structure and controls the order based on the success or failure of its children.
- Selector: selector composition - will execute the child nodes below it.
- Attempts to select the most appropriate task-child returns success, selector succeeds. All child nodes return failure and the selector fails. (Success if any task succeeds. Fail if all tasks fail.)
- If the first branch returns false, the next branch will be executed until a branch returns true and the Selector node is executed.
- You can place the highest priority tasks on the left.
- Squeencer Composite - The Sequence Composite node traverses the child nodes in sequence order, and it succeeds if and only if all child nodes return success. If a step fails to execute, it fails.
- The first branch returns true, then execute the next branch until one branch returns false
- Simple Parallel: Parallel
task node
Task: The specific execution node of the behavior tree, which can be understood as the current action of a character, which can be executed and returned after one frame, or can last for a period of time
- A node of the Behavior Tree, no other nodes can be added below it.
- is the end of a behavior tree branch (but not the end of a behavior tree!).
- Also known as "leaf nodes"
Task status: success , failure, execution. (The next node is executed regardless of failure. The order is from left to right.)
Customize the task after pressing New Task, customize the event of the task
Complete the task (this node is necessary, otherwise it will be stuck in the current task and cannot continue to execute)
set variable
decorator
Decorator: It can be understood as the conditional judgment of the Task, and the Task will be executed only when the condition is true
add decorator
The decorator is equivalent to if, which executes one task if the condition is met, and executes another task if the condition is not met
- The execution logic of the behavior tree is from left to right, and the observer stops, which can be understood as follows,
- Self is the ability to interrupt oneself
- Lower Priority is able to interrupt the node on the right
- Both are both
- When the second node is executed, the decorator of the first node meets the conditions, and Lower Priority will interrupt the execution of the second node and execute itself.
- When the first node is executed, if the result of the Actor changes, Self will interrupt the current Task and start playing from the beginning, that is, RunEQSQuery
- Both can be interrupted in both cases
Serve
It can be understood as binding to a node. When the state under this node is executed, the service will always run at a certain frequency
create service
Custom Service (New Service)
Execution order of overloaded functions: decorators with loops hanging on nodes
When executing to the current service node, the execution order
----- Execute the event first to receive the search and start the AI
----- Re-execute event receiving enable AI
---- Events will be executed during the Loop process, event reception, search and start AI
----- The end node will perform event reception to disable AI
combine
Tasks and Composites can create various ways to handle AI behavior.
Don't worry about how to complete the task, just make a decision to complete the task.
Attributes
BlackBoard: Whether the variables in the blackboard have changed
Composite: Combine multiple Boolean values
Cooldown: Wait 5s before executing
Blackboard (for use with Behavior Trees)
It can be regarded as the creation of some public variables of the behavior tree, and the variable value of the behavior tree blackboard can be modified externally to achieve the logic of modifying the state of the behavior tree
create
Create variables in Blackboard
EQS Environmental Query System
EQS (Environment Query System) - allows AI to take into account a variety of environmental factors, to be used with the navigation grid
create
interface
Take Points: Circle as an example: an object that generates a ring around the query { Cricle Radius: the radius of the ring Space Between: the distance between every two points Number Of Points: the number of points
}
renderings
EQS to test
Distance: distance test
Pathfinding: whether there is a path between the two
After adding the test
Specific attribute
Test Purpose: test purpose (Filter Only: filtering, Score Only: scoring)
Score Equation: scoring mechanism (Liner: the closer the distance, the lower the score, Inverse Liner: the farther away, the higher the score, Square: the square trend changes)
Create an EQS character (for testing EQS), place it in the scene after creation
Select which EQS to test in the test role
The parameter you add is set in the blueprint via the "Set Named Param" node, and its target is an EQS instance reference, which you can get from the "Run EQSQuery" node.
Associated EQs in Behavior Trees
example
ray detection: LineTraceByChannel(detect lines by channel) {
Start: starting point (world coordinates of the player camera) (First Person Camera+GetWorldLocation)
End: end point: getforwardvector to get forward vector * distance + current location (GetWorldLocation) = end position
Draw Debug Type: whether you can see the emitted rays (can be The option is None, For One Farme one frame, For During duration is reserved, set the time at the expanded position)
Actors to Ignore: Objects to ignore
Trace Channel: There are two types of Visibility and Camare in the node, which must be recognized by ray detection When the collided object is found, the corresponding channel will be opened in the collision part of the object details panel to be detected. Therefore, the relevant channel of the corresponding object to be detected should be set to block and be consistent with the ray detection channel, and the ray detection and recognition can be performed.
}
Make Arry: create an array
set a decorator variable