Making enemies chase the player
There are two main challenges associated with making enemies chase the player that we need to overcome, making the player believe the enemy is showing intelligence and is hunting them down. They are as follows:
- The first is that the player is near enough to the enemy so that the enemy may see or hear them. You don't want enemies to start chasing players when they are on the other side of the map, otherwise, the effect is lost and isn't believable.
- The second is that the enemy is facing the player when they start chasing. If the enemy is walking in the opposite direction, the player might be able to sneak past them without the enemy noticing. So we won't make them chase when they are not even facing the player.
To overcome these challenges, we will track the distance between the player and enemy at every update, which happens 60 times per second. If the distance between them is below a certain value, and if the angle...