Zombie Runner Enemy AI Discussions

I’ve merged a few lectures into this one forum post. If you have anything you’d like to ask or discuss regarding the early implementation of our Enemy AI, here is the place for it.

Thought I’d share a small change I did for the Chase Range lecture. Once the enemy AI starts chasing you, I thought the distance to get it to stop was too small, so I got the chaseRange to update once he starts chasing you.

    if (distanceToTarget <= chaseRange)
    {
        navMeshAgent.SetDestination(player.position);
        chaseRange = 8f;
    }
    else
    {
        chaseRange = 5f;
    }
4 Likes

Good idea!

1 Like

I couldn’t resist. Here’s a Voxel Dalek I made: https://skfb.ly/6LDG7
I made it available for download on Sketchfab. #exterminate

4 Likes

Yay!

Exterminate! :smile:

I know Rick said that I shouldn’t spend more than 1 minute with the enemie’s nose but I just had to do it xD

Enemy

Edit:
Maybe I’m wasting way too much time with unnecesary things… xD

6 Likes

Worth it!

1 Like

thanks man, great idea. gonna copy!

1 Like

I am having the following errors when I try to place my enemies too far away from the player on start.

This is the error I get when the game starts.

Failed to create agent because it is not close enough to the NavMesh

Then when I try to shoot it from a distance, it gives this error.

"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
EnemyAI:ChaseTarget() (at Assets/Scripts/EnemyAI.cs:95)
EnemyAI:EngageTarget() (at Assets/Scripts/EnemyAI.cs:64)
EnemyAI:Update() (at Assets/Scripts/EnemyAI.cs:31)

Will this be fixed in later videos, or did I maybe do something incorrect?

After a lot of searching and trial and error, I found out this error comes from not baking again under the navigation tab. Basically the AI can’t determine the route to get to you so it crashes. To avoid this crashing on me in the future I wrapped my chase target with if (navMeshAgent.isOnNavMesh) { so that way I will notice there is something wrong, but it doesn’t crash the game.

Nice

Disclaimer: These assets are not mine. They are from the Synty Apocalypse pack.

I’ve gotten into the habit of anticipating what the video is going to have me doing. Here is my solution to the chase range AI (video 172). It is assumes that there are multiple possible targets, finds the closest target, and then notifies all listeners.

The component Search For Targets looks inside of an overlap sphere for all objects in a given layer. Then, it determines the closest one and triggers a custom Unity Event. In the inspector, the Set Target method of Follow Player is set by the event from Search For Targets.

Here is my Attack if Provoked implementation:

And here are the adjustments I made to equip myself with a gun.

2 Likes

Here’s my progress so far with the basic enemy chase/attack functionality :slight_smile:

2 Likes

Hi,
After giving the player a gun (with muzzle effect and hit effect), why does the enemy not get provoked when it is hit by a gunshot?
Currently it only gets provoked if we are in enemy’s chase range.
(I’ve completed till “Create Player Health Class” lecture)
So, is that going to be fixed in a later lecture or did i miss it in some lecture till now?

found my answer

Since you mentioned Doctor Who, I had to add a Dalek to the game :slight_smile:

1 Like

Privacy & Terms