Journal 70 — “The Great Fleece” in Unity, Finish Guard AI

Objective: Complete rest of functionality for security guard AI

In “The Great Fleece”, we just implemented the first guard AI animations between waypoints. Now we want to finish the other two security guards patrolling between the display cases.

Guard Waypoints

First, we need to create one additional waypoint for the stationary security guard in order for the animations to work. The last patrolling security needs 4 waypoints, since he will be able to choose a couple different routes.

After creating the new waypoints, you can drag them into the two other security guards Inspector and also add an Animator component.

In the GuardAI C# script, let’s make two updates: add a null check for the animation, and a check before the waypoint movement that if there is less than 2 waypoints, meaning 0 or 1, then just return, and skip the waypoint movement.

Now let’s see this in action.

Add “Eyes” for Game Over

Let’s add a trigger to act as a set of eyes in front of each security guard while they are patrolling. If Darren triggers this, it is game over. Add a 3D Cube to each security guard, turn off the mesh renderer, scale the box collider to an area in front of the guard, and turn on the box collider trigger.

Now let’s add the functionality in a new C# script called Eyes that is added to each box collider.

And finally, let’s see how this works in action.

Bonus, fix Main Camera start

As we make adjustments to the game, the Main Camera may get shifted to another camera view, such as during a cutscene. One last fix is to make sure the Main Camera starts in the beginning position. We can do this in the CameraFollowPlayer script, by adding a reference to the first camera view, and setting in the Start method the position and rotation.

You can test this by moving the main camera and setting another camera view and then pressing playmode.

Thank you for your time!

--

--

--

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Go Microservices with Go kit Using Mongodb and Mysql

CS371p Fall 2020: Benjamin Cheatham

With Planet 4, each Greenpeace office will have its own Wordpress instance

Custom CMS Development Services With Amazing Features

Graph Data Structure using Java

A small take on the work-from-home situation in Lebanon lately

Java8 Features Card

Build a simple guessing game in Golang.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chris Nielsen

Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.

More from Medium

Journal 151 — Unity Project Development, 2.5D Shooter

A low-poly knight 3D model!

Framing Transposer Virtual Camera Explained in Unity’s Cinemachine

Introducing Stream’s New SDK for the Unity Gaming Engine