More on the AI System
- The perception system.
- We can add "senses" to an actor
- This is done via a AIPerception component.
- These can be customized to recognize a set of "senses"
- Players with this have a OnTargetPerceptionUpdated event
- Triggered when a stimuli is perceived.
- Triggered when a stimuli stops.
- We can also add "Stimuli" to an actor
- This causes the item to generate "stimulus"
- This is done via a AIPerceptionStimuliSource component.
- He demos how to configure these.
- And how to debug these.
- In the end, he sets up a blueprint on the AI character
- This registers an actor that has been perceived.
- IE the AI character "remembers who it saw"
- And removes this actor a bit after it is not longer perceived.
-
- Behavior Trees
- First introduced about 2004
- Still a topic of research
- They represent a way to implement complex agent behaviors.
- Some tree terminology
- Trees are represented by nodes (or points in the tree)
- And edges connecting these nodes.
- The edges are directed.
- The node at the top of the tree is known as the root
- The nodes at the bottom of the tree are known as leaves.
- There are no cycles or loops
- Every node but the root had exactly one parent.
- But a parent may have many children.
- In behavior trees, control flows
- From top (the root) to bottom (the leaves)
- From Left to right among equal children.
- In general, nodes in a tree represent a task
- They can be
- simple, just a single task
- composite: the combination of several tasks.
- Task Status
- A task can be
- Running
- Successful
- Failure
- Composite nodes are
- Selectors
- It will execute the nodes below it.
- It is considered successful if any of the children nodes are successful.
- It will fail of all nodes fail.
- Example: eat dinner
- Look for something pre-cooked in the kitchen
- Try to cook something
- Order something delivered.
- Go to a restaurant.
- By placing the nodes in order (left to right) we prioritize which task to attempt first.
- Again, this succeeds if any one task succeeds.
- And it only does tasks until one is successful.
- Sequencers
- This will execute the nodes below it.
- For this to be successful all nodes must succeed.
- Example: Prepare dinner
- Find a recipe
- Get the ingredients
- Follow each step of the recipe
- Place the food on the table.
- Again the steps are in order.
- If any step fails, the entire operation fails.
- There is a third composite node, simple parallel.
- These have two sub nodes
- The first is a simple task.
- The other can be a complete b tree
- It will attempt to execute both.
- Document example
- Attack an enemy while moving towards a goal
- The first task is primary.
- The second task is secondary.
- Together these concepts lead to an incredibly powerful system.
- Nodes can have one or more decorators
- These use blackboard variables to determine if the node should be executed.
- Practical Behavior Trees
- These consist of two components.
- The behavior tree.
- A blackboard.
- Sort of what the name implies
- This is a global storage space for the behavior tree.
- Think of it as working memory.
- In the demo he has you build a task (leaf node)
- BBT_FindNaviagble Location
-
- Then jumps to a completed tree
-
- The intermediate steps are
- Return to the Behavior Tree.
- Right click and select BTT_FindNavigableLocation
-
- Set the
TargetLocationKey
to be the TargetLocation
-
- This is how you link the individual values on the blackboard to the tasks in the tree.
- The root will only all composite nodes, and we need to do three tasks so we will use a sequence.
- Drag off of the box at the bottom of the root.
- Select Sequence
-
- Add a MoveTo task
- Set the Blackboard Key to be Target Location
-
- Finally, add a wait node.
- Communicating to a blackboard
- He does this in two stages
- He builds communication functions in the controller.
- These take parameters and set values in the blackboard.
- This is done via a "key" or the variable name in the blackboard
- I assume they implement the blackboard at least partially as a hash table (Map, Dictionary)
- As such, the key name must match the backboard entry completely.
-
- Then he calls these functions from the other code.