Expanding Enemy A.I. Behaviour


Introduction

this week i worked on expanding the enemy AI and its behaviours. it can now guard a location, patrol a set path, and wander the map (sort of). expanding upon the work done last week, the enemy will detect the enemy within its detection radius and stop patrolling, guarding or wandering and chase the player to attack them. If the player managers to escape the enemy the enemy will linger around the players last known position for a few seconds before returning to what it was doing before.

There were a few things i had hoped to implement, the view cone to expand on the detection radius, this proved to be more challenging than i had thought and i ran into issues with it. When the enemy gives up chasing the player, instead of waiting a bit before it returns to its last job, it decides to skip the wait process and go straight back to work. you will recall i said the enemy will sort of wander the map, it turns out it wants to completely ignore the map and float around the outskirts instead, hmm.

Goals

1. have the enemy stand guard at a position,

2. have the enemy patrol along a path,

3. have the enemy detection radius extended with a view cone,

4. have the enemy idle at players last known position when chase has ended,

5. have the enemy wander around the map,

Resources

the Enemy A.I. Lectures in this Udemy course really helped me understand how to implement patrol method

Issues and Risks

Enemy don’t wait before returning to their assigned roles, i believe it to be an issue with the timers not updating correctly. for now, the method has been removed from all other methods that may call it.

Patrollers are also meant to idle for a short amount of time from waypoint to waypoint, this is ignored, again i fear it an issue with the timers.

Enemy are supposed to wander the map, instead the mesh warps outside of the mesh while the collider runs the extents of the map via the NavMesh. I’m not sure why this is happening but i didn’t have time to integrate it into my MoveTo() method.

When creating the PatrolBehaviour() method i had issues getting the patrollers to start patrolling, or patrol at all for that matter. eventually i managed to get it working after disengaging the player when chasing, they then moved back to the guardPosition and immediately to the next first waypoint, this made it easier to debug what was causing the issue.

below, a gif of the patrols and guards, then i set one guard to wander


Leave a comment

Log in with itch.io to leave a comment.