top of page
Search
  • Writer's pictureNg Wei Shun

Scavenger's Hunt Devlog 2: Enemy Detection

Welcome to Scavenger’s Hunt Devlog 2. The current version of Scavenger’s Hunt can be found on Stencyl Arcade.

Scavenger’s Hunt is my attempt on making a stealth game set in a post-apocalyptic world. So, what’s a stealth game without enemy detection?


To give some context on how enemy detection works in stealth games, one of my favourite Flash stealth games I’ve played as a kid is The Classroom. The player, where you play as a student trying to copy your classmate’s answers without getting caught by the teacher. In the game, the teacher has a cone of vision. If you get inside the cone at any point, you lose.


First, let’s set some conditions for how our enemy will spot the playable character. (I know these conditions below aren’t exactly the best ways to code for detection, but they will suffice for my game for now.)


In order for someone to see an unwanted guest on their turf, they first have to face the same direction that the playable character is at. In the current setup of the game, the playable character will always be on the enemy’s left. Thus, the enemy has to be facing left for them to see our player.


Also, let’s give the enemies a fixed range before they see the playable character. This means that the difference in their horizontal positions must be below a certain number. They also should be on the same vertical plane, as it does not make sense that an enemy can see you if they are within a certain horizontal distance but is on a floor above you.


Lastly, in order to make the game more interesting, I made a hiding mechanic. In certain areas, the player can hide to avoid being seen. Thus, the enemy can only see the player while they are not hiding.


So this comes out to:

1. Enemy facing the direction of the player

2. The player is in detection range (horizontal and vertical)

3. The player is not hiding


Next, let’s define what happens when an enemy sees the player.


Since the enemies only carry a knife, they have to get up close and personal to attack the player. As sinister bandits defending their turf, they won’t like it when people try to steal their supplies. So, let’s have them be angry when they see the player, which causes them to move towards the player at an increased speed.


I also gave them extra health if they see the player, so that it will be very hard for the player to kill the enemy once they are seen and makes backstabbing the enemies a better choice. This encourages the player to play stealthily instead of getting right in the face of the enemies.

Although this code works fine design-wise, it looks buggy if the player leaves the same vertical plane as the enemy by climbing the ladder. Currently, if the player climbs up or down the player after being seen, the enemy will stop where they are, but stays facing left, causing the player to lose the game as soon as they get back to the same vertical plane. Even though this enforces the fact that players should lose as soon as they are seen, it looks as if this was an unforeseen situation that is not coded in.

There are two solutions to this problem. A: make it so that the player instantly loses as soon as they are seen and the level resets, or B: the enemy goes back to their starting position and continues patrolling.


I used Solution B, as many games with stealth elements, such as Assassin’s Creed and Far Cry, choose this as well. Although it makes the game easier, as players can just climb the ladder to reset the enemies, I feel that making the players lose as soon as they are seen is very frustrating and not fun. Besides I can also increase the enemies’ speed and decrease the time before they changed direction to increase the difficulty, which I did.


This is how the final code looks like:


Again, I’ll emphasize that there are some problems with this code if I use it on a full-fledged game. The biggest problem is that the player won’t be seen if the player is on the enemy’s right. Though, this can be easily added by adding a condition that checks if the difference of the enemy and the player’s horizontal positions are not more than a fixed negative number, same as I did for the y-axis.


Another way to code for the detection is similar to the one used in The Classroom, where a region or actor will follow the front of the enemy, and the player is detected if they are inside the region. Though, I felt that this method was harder to code and also visualize.


And that concludes the two mechanics that I made in Scavenger’s Hunt that taught me a lot. However, I feel that these mechanics can be improved further with more definitions of how detection starts and what happens when it ends, so I hope I can revisit this mechanic in the near future.

8 views0 comments

Comments


bottom of page