Shoot himself? If only that was the only thing!

After the enemy is dead, move away from them and behold their beyond-the-grave strong will!

2 Likes

He moves after death throughout the entire past section course, and also, he has a machine gun, he could kill us very easily if he wasn’t too busy dealing with his guilt

Howdy, thanks for bringing this up!

I found a solution that worked for me if anyone else is interested in fixing this(I am very new to programming & game development so if anyone has a better idea of how to do it, let me know!)

If the AI enemy is dead, it doesn’t need to execute any movement or shooting related tasks in the behavior tree, right?

So, I made a new blackboard key, named it “IsAlive” & made it a bool(for bool keys, “Is Set/Is Not Set” is the same thing as “true/false”, respectively).

Then, I added a new selector branching off from the root selector that has no connected tasks.

I then added a blackboard decorator to each selector, set both of their blackboard keys to “IsAlive”, set the original selector’s key query to “Is Set” & the new selector’s key query to “Is Not Set”. I also set the original selectors Observer Aborts to “Both”.

In other words, if the “IsAlive” bool key is set(true), all our tasks execute normally. BUT, if it is NOT set(false), no more tasks will be executed.

Now, the only thing we have left to do is implement a way to clear the IsAlive key when we die. Fortunately, this is going to be really simple because we already have an IsDead() function in our ShooterCharacter class.

Step 1. Make sure we have our ShooterCharacter.h #include in our ShooterAIController.cpp. Then, we will set our “IsAlive” key value to true using the SetValueAsBool() function in BeginPlay() just like how we set out vector values.

Since we need to check if the IsDead() function is returning true, we need to grab ahold of the ShooterAIController’s pawn & cast it to a ShooterCharacter(I named mine AICharacter). Finally, we just do an if statement to check if there isn’t a nullptr && if AICharacter->IsDead() returns true. If both of those conditions are met, we can clear the IsAlive key.

Bam! No more following/shooting corpse!

Also, I think adding this secondary BT Selector may come in handy later incase there’s any other behavior we want to tie to death.

Again, if any more experienced programmers see issues with this solution that I may be missing, let me know!

Privacy & Terms