Shade's Peak - AI


Implementing AI 

The enemies in the game run on simplistic finite-state machines. Their normal state is to idle, and they consistently have the distance between the player and themselves calculated within their game object. Once this distance reaches below a certain point, as in the sight range, the enemies will begin chasing the player. And once this distance reaches yet another point which is lower than the sight range, the attack range, they will stop chasing the player, look at them, and try to attack them. If the player does leave both ranges, then the enemies will simply stop chasing them. 

The original AI did have a few problems, such as if there was a wall between the player and a ranged enemy while the player was in attack range then the ranged enemy would just do nothing but just shoot at the wall since both requirements were technically fulfilled. This issue was fixed by requiring an enemy to fire a raycast and having this raycast hit the player before the state-machine went to the attack rather than chase path.

 If the enemy’s raycast can hit the player then they will enter the Attack state. What the attack state does depends on each enemy such as for the ranged ones it has a 90% chance of firing a fast normal projectile, and a 10% chance of firing slower one which can snare the player.

We did have some problems when it came to the AI feeling a bit slow and not aggressive enough at times, while in addition we had a second problem being that the AI would run into issues whenever they were locked up in a room. 

So to solve the first problem we added a consistent transform.LookAt(player.position) which would immediately cause the enemies to always be looking at the player thus not requiring a wind-up time for them to engage in combat and we also increased their movement speed thus making them consistently chase the player.

For the second problem we added more conditionals for whenever their AI should be activated as so the enemies would move erratically in place while in a locked room because they did not find any viable paths to reach the player.

Files

SilverFog_BUILD_FINAL.zip 353 MB
Jul 24, 2024

Get Shade's Summit

Leave a comment

Log in with itch.io to leave a comment.