Enemy Creation

I'm creating a fps speedrun game so obviously there need to be enemies that will try to prevent the players from progressing. They need to be balanced so that it won't be too hard nor easy for the player to progress to the next stage. It needs to be very hard for players that jump in without a plan, and it should be very doable for players that know the level layout.

There are a few things I must take into consideration when creating the enemies.

  • Models (size)
  • Health
  • Shooting at player
  • Movement (going after player)

Models

I started by getting a model of Mixamo.com. It's a very good website to get models + animations and because modelling/animating isn't my focus this project, I will gladly take it as is. I took a model of a mouse with "aiming idle", "walk & aim" and "death" animations.

Health

After I implemented this in Unity, I worked on the enemy health so the player can kill the enemy. I took the healthbar I used for the player and placed it in a 3d worldspace canvas above the enemy's head. I then implemented the shoot mechanic which you can see in the third screenshot. When the player hits an enemy, it will calculate damage with an algorithm I made. The enemy then takes damage and when its health is 0, it will die.

Shooting at player

Now that the player can shoot at the enemy, the enemy needs to be able to do something back. For that, I created the "ShootingAI.cs" and "FieldOfView.cs" scripts. First the FieldOfView.cs script is used. It is used to help the enemy find the player. As seen below it checks multiple things.

  • Is the player within the range of the enemy?
  • Is the player withing it's field of view?
  • Is the player not behind an object?

If these questions all answer yes, the enemy will be able to see the player and it will start shooting (ShootingAI.StartShooting();).

The white circle below is the range and the yellow lines are its field of view. These are adjustable values.

The enemy will shoot at the player every second. The damage calculator is the same as for the player which makes shots more effective when you're close. It makes it a high risk, high reward tactic to get close to the enemy. The enemy though, has a chance to miss the player.

Movement

Last, but not least, the enemy needs to be able to move towards the enemy. I used a NavMeshAgent for this. It also uses the FieldOfView.cs script and when it sees the player, the NavMeshAgent will move towards the player.

Maak een gratis website. Deze website werd gemaakt met Webnode. Maak jouw eigen website vandaag nog gratis! Begin