top of page
James Burke

Individual Project #8 - Behaviour Trees C++

For more complex and manageable AI, I have opted to convert my AI to a system where characters have AI controllers, and AI controllers run behaviour trees. Then the behaviour trees are what handles the actual AI behaviour. In addition, I have attempted to achieve a certain balance of C++ in this revised (work in progress) implementation.


AI Controller

For the controller, I simply get a reference to the player pawn of the world before running the behaviour tree (where the reference is provided through the BP editor).


Behaviour Tree

So far, the selector begins with a service which updates the Blackboard key for the player location if they are in the line of sight of the AI. This is implemented in C++. If it is found that the player is visible to the AI, the "Chase" sequence occurs. If the player is no longer in sight and if there is a reference known to the last known player location, the AI will attempt to locate the player by moving to where they last saw the player. This should, in further updates to the game, follow by moving around a certain area. If both sequences fail, the AI returns to their original position.

Chasing occurs through the basic MoveTo task node. The goal of chasing for the AI is to get close enough to the target to initiate an attack.

As long as the player is within the attack range, a node will be called to melee attack, followed by delays (three wait nodes).


Firstly, time is alloted to account for the attack animation time. Secondly, time is given to give a gap in between consecutive attacks (as the enemy will attack on loop as long as the player is in range). Finally, if the player goes out of range, the second wait node is aborted and the third is initiated- this third wait node gives a delay before the AI resumes chasing the player. This is a design choice to make the AI more fair.


Melee Task Node C++ Implementation

Here, we get references to the enemy pawn of the AI owner, and the player pawn before calling the Melee function of the enemy character class, where the functionality including damage and animation handling occurs.


C++ Service Implementation Example

Here we get the player pawn and check if the AI owner has a line of sight to the player pawn. If it does, then the location blackboard key will be set, otherwise it will be cleared- this will signify that the player is not currently visible. This functionality was previously in the AI controller's tick function, however I have moved the implementation over to services which is more performant as services can be set to run less frequently than tick.

Recent Posts

See All

コメント


bottom of page