The Advanced Companion AI uses a built-in perception system to respond to the world around it. This section explains how we implemented this built-in system in the Advanced Companion AI.
Used Perception Features
The Advanced Companion AI uses the built-in perception system to respond to the world around it. It uses "visual sensing" to see enemies, "noise sensing" to tell the player when it hears something, "damage sensing" to react to actors applying damage to it and "predictive sensing" to predict the player's location to provide more immersive in-game behavior.
Visual Sensing
When the AI senses a pawn that has the “enemy” tag, it will be seen as an enemy and the AI proceeds to attack. For this the AI controller checks if the detected pawn is an enemy and if so, sends information to the blackboard, telling the AI that it is currently in combat and setting the enemy object reference. Please note that the enemy must be of the “SimpleEnemy” class for the system to access the “Dead” variable to check if the enemy seen by the AI is still alive or not. If you want to use your own class, just make sure to add the “dead” variable to it and replace the cast node in the AI Controller (AI Visual Function).
Noise Sensing
The AI is able to hear noises in its environment. If the AI hears a noise, it wont take direct action. As soon as the AI hears something it will trigger a pop-up message in the HUD Widget informing the player about the noises. The AI only follows this behavior if it is currently not in combat.
Please note in order for the noise sensing to work properly, each sound that you play for the AI has to contain the “AI Companion Sound” so the AI is able to recognize it.
Damage Sensing
When damaged, the AI it will inform the player that it has been attacked, by triggering a pop-up message using the HUD Widget and then proceed to attack the pawn that applied damage to it.
Since the whole damage sensing logic is executed in the AI controller, you can’t just apply damage to the controlled pawn and expect that the AI controller will recognize this damage. The “Register Damage” event is a custom event and must be called every time the controlled pawn is damaged.
To save you some time, we included the “Damage Companion AI” function to the general companion functions blueprint library. You can use this function just like the “Apply Damage” node with the only difference that this function also informs the AI controller about the damage. The function can be called from everywhere in your project.
Predictive Sensing
The AI uses predictive sensing to predict the players future location. We already explained why this location is needed so scroll up for the full explanation.
The AI uses predictive sensing to predict the future player location. This location is then used by the projection system to provide a precise location to the “For Run” follow method.
Learn more about Unreals AI Perception
Below is the currently active link to Unreal's official documentation on the AI Perception System. There you will find all the information about the system provided by Epic.