The Problem:
After implementing most of the Base Enemy Behavior Tree, I decided it was high time to do some house cleaning. The Behavior Tree had become cluttered with all these different branches for all the different states that it became difficult to understand the logic nor navigate the tree for play testing. As a result, I decided to remove some of the branches and create sub trees for the specific states.
From there, I created a handful of a behavior trees to house very specific functionality. In this case, I create a sub BT to control the passive state. This sub tree controls the enemy’s ability to randomly patrol within the environment when not agro’d or in other words, made aware of the players presence. Prior to migrating the functionality, the BT worked fine. It was only after I created the sub tree that everything stopped working.
If I undid the work, everything worked, but whenever I incorporated the sub tree, the enemy AI would just remain in place. Unless I got within view of the enemy, it would just stand their idling stuck in their passive state.
<Reference Image of the enemy AI not patrolling in their passive state>
<Reference Image of the enemy AI not patrolling in their passive state>
<Reference Image of the sub behavior tree not saving the new location to a destination but instead to its self>
The solution:
After a considerable amount of debugging, I spotted the issue. As always, it was a simple mistake. When I copied over the logic from the enemy base tree to the sub tree, all the Blackboard keys got reset. What was happening was the enemy would look for a new location, save it, and then walk towards it. Normally the enemy AI would save the location in a vector. Because the Blackboard keys reset, it meant that the enemy AI was saving the location not in a vector, but instead was attempting to use the enemy’s location to save the data to causing the enemy to remain in place.
<Reference Image of blackboard keys>
After updating the Blackboard keys to appropriate variables, the enemy AI once again patrolled aimlessly within the environment until it either spotted the enemy or was stuck by the enemy at which time it the enemy would switch into its attack state and aim to kill the player.
<Reference Image of the enemy AI patrolling in their passive state>
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.