Enemies and Interaction


In this devlog we get to one of the cornerstones of this entire project: the enemy AI. This has been a difficult thing to get working and only recently has the AI been in a state that I would consider "functional". 

The enemies need to be able to:

  •  see the player
  • chase the player
  • attack the player
  • navigate the environment while doing all of the above.

Currently the enemies can navigate the environment, see the player, chase the player, and attack in close and long range. Things that still need work are: 

  • the enemy's ability to remember where the player was last seen when they exit line-of-sight (LOS)
  • the enemy's ability to follow a defined patrol path, and return to that path when they are finished chasing the player
  • Optional: the enemy's ability to hear when the player shoots, then head towards that position

Enemy Line of Sight & Detection:

Above this post is the code for the "PursuitRay" function which allows enemies to examine their environment and detect the player. Upon start, the enemy is informed of what the player looks like so they know who their enemy is. You can also see that I'm instantiating an animator and shooter component, which allows the enemy to change behaviours depending on whats happening in the scene and how to shoot their gun respectively.

Each frame, the enemy is checking if the player is in sight. If the player is within LOS, then the enemy enters the "spotted" behaviour, which we'll cover a bit later, and they also begin firing their gun at the player.

Here you can see how the raycasting function works. The enemy "knows" where the player is at all times, but will essentially pretend they cant see them. Once the player is in view of the enemy, the behaviour changes as described above, triggering the chasing and shooting behaviour.

Enemies have a functional health system as well. They can take 2 shots before dying, meaning the player has to be able to be accurate enough to hit those 2 shots from a distance, or risk getting close enough to make that easier.

One of the new features introduced with this devlog is the stealth box, my personal favourite feature of the entire game!

As I've mentioned in previous devlogs, the stealth box allows the player to temporarily hide from enemies for up to 5 seconds, which will consume a charge, which the player will have a max of 2 at one time. Extras will be placed throughout each level (currently indicated by the pink cylinders you can find in the prototype build).

Feedback:

One interesting piece of feedback I received was to add some sort of indicator over the enemy's head to show the player whether or not they've been spotted. This is a relatively easy thing to implement, so that will definitely be in the next build.

Other feedback I received was on the speed of the enemies, specifically that they were too fast for a stealth game, in future builds I'll spend some time tuning the character speed until it feels more in line with the pacing I want for this game.

Finally it was pointed out to me that sometimes the enemies can see through the stealth box that the player can use to temporarily hide from enemies, which obviously defeats the purpose of the stealth box entirely, so I'll be working on that for the next build too.

Leave a comment

Log in with itch.io to leave a comment.