Problems with Enemy Detection


Reported By: David Tarnowski

September 15, 2023

THE PROBLEM

This week I ran into issues with the enemy AI detection that caused problems for gameplay and the user experience. The enemies were not properly detecting and engaging the player character, even when standing still right in front of them. Instead, they would endlessly walk in circles without initiating their attack behaviors. This also caused the AI to rapidly flip between their "pre-combat" and "in-combat" states nonstop, which further impeded the enemy AI. 

From a gameplay perspective, the enemies were not providing any challenge or threat to the user since they failed to ever attack. It also hurt immersion as the AI behavior was unrealistic. I needed to address this promptly as enemy detection and response ties directly into our core combat loop which is essential to keeping players engaged.

THE SOLUTION

The root cause of the erratic enemy movement and detection issues was that the scripts were referencing the wrong game object's rotation when calculating directional facing and movement. I had originally used the rotation of the game object that the script was attached to, rather than the enemy model itself. To fix this, I changed the scripts to instead reference the actual enemy character's transform rotation when determining which way to move and look. This ensured they were properly rotating and moving based on their own orientation rather than that of the logic game object. Additionally, I added logic in the pursue state to halt movement once within attack range and sight of the player.

 Before, they would endlessly walk in circles around the player while in pursuit. By stopping movement on detecting the player, it forces the enemy to pause and initiate attack actions, rather than nonsensically passing by them. These fixes resulted in more realistic enemy behavior and consistent transitions into combat once the player is detected.

Get Psyche

Leave a comment

Log in with itch.io to leave a comment.