Adding more awareness to AI
What i want to do?
If you see another fella being shot, the most common reaction is that you will face the direction that shot came from (to prevent you getting shot, of course) and then run around to check if there really is a fight going on. Besides that, I also want all of the enemies in the room to be alert when their fella is down!
What do I already have?
Barely nothing since there is no way to indicate that there is an enemy down except a DeathFeedback. At first I thought I could use that to send an event to a nearby enemy but I found out that creating a new script and putting it in the enemy corpse gameobject is the less messier way to go.
What did I do?
I create an EnemyDeathAlert script and abuse the start function.
To add Player as the target, the first thing I need to do is to get all the gameobject that have the layer “Enemy”. Then add those gameobject to a List
Then for each of those gameobject, I send a raycast from the gameobject transform to the corpse to check if there is any wall in the way.
If the raycast returned true, then it did hit a wall.
If not, I create an array and add the player to the brain.
This will result in the player position in the last location assigned to brainTarget. The last step is to design the AI by adding more script to the behavior, the AI behavior can looking a little bit like this:
By creating AIDecisionDetectDeathAI2D and combining it with AIActionOrientateToTargetLastPosition2D, now the enemy AI can detect the player position and point their gun toward you, neet. Looking back at the function, maybe it was more logical if I alert the enemy when you actually enter a room and then fire your gun. Maybe in the future, right now I am very happy with what I created.
Comments
Post a Comment