Zombie FPS Progression Report: New Zombie AI Unity3D

Mohamed Hijazi
Geek Culture
Published in
3 min readJul 5, 2021

After implementing the new Zombie AI using a character controller(read here => Zombie Progression Report: Enemy Prototype and new Player Character), I saw that the AI was a little dumb. If there is an obstacle in front of the zombie, the zombie will not try to find a new path towards the player. Yes zombies are kind of dumb, but still this would not be fun.

Character Controller getting stuck

As you can see, the zombie just got stuck behind the cubes and couldn’t calculate a new path towards the player.

Before going into how I solved the above problem, let me introduce you to the first zombie. It is a slow moving basic zombie, that sniffs the player when they get close and start chasing and attacking them.

Slow Zombie

Fixing Zombie AI

In order to solve the path finding problem, I changed the enemy movement from the Character Controller to NavMesh based movement.

Basically I NavMeshAgent component to the zombie and removed the Character Controller. Now the destination of the zombie is set by the nav mesh agent. Of course, I had to add to bake the navigation into the scene (I will write a more detailed article about it).

Some refactoring had to be done for the chase radius, the navmesh stopping distance and speed. The stopping distance is now assigned based on the attack distance of the zombie, and the navMeshAgent speed is assigned based upon the zombie speed.

New Zombie AI

As you can see now the zombie can intelligently find a new path towards the player and almost never getting stuck behind obstacles.

Zombie Animations

Headshot multiplier

Zombies, nothing is better than shooting them in the head. I added the ability for the player to shoot them in the head and having the a damage multiplier for headshots.

I did this by adding to empty game objects to the zombie with trigger colliders, one for the head and one for the body.

I added the above script to both gameObjects, and we can detect if we are shooting a head or a body and apply damage accordingly.

--

--

Mohamed Hijazi
Geek Culture

A knowledge seeking biologist who is following his passion into a full time career in Unity / Game Development. https://www.linkedin.com/in/mohamed-hijazi/