Make Guard Stop When Reaches a Waypoint

Objective: check when the guard reaches the first and the last waypoint and stop him for a few seconds.

When I created the guard waypoint system, the functionality made a continuous movement. Now I want him to stop in the first and the last waypoint.

In the GuardAI script I declare a bool variable called targetReached. The idea is to use this variable as a flag to execute or not the guard movement.

Next I created a coroutine called WaitBeforeMove. This coroutine sets the value of targetReached to true, waits 5 seconds and sets the value to false.

In the update function I check if the targetReached is equal to false in the first if statement. If targetReached is true it means that the guard is in the waypoint and he has to stop.

Then I added another if statement to check if the currentTarget is the first or the last waypoint to call the coroutine. With these 2 conditions the guard is ready to stop when reaching the first or the last waypoint.

And that’s it!!! Now the guard makes a stop before continuing on its way.

--

--

--

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

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

Recommended from Medium

8 Powerful Tips That Will You Save More Battery On Android · Topguide

Learn By Doing Android, Diving into RxJava & RxAndroid (Concurrency)

How To: Implement Video Call on Android with Two Lines of Code

Android App Bundle and Play Instant

Android Kotlin Coroutines

Firebase SDK integration and Phone Number Verification

Push Notifications React Native (Android)

Android Reversing — PinBreak

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
Rusben Guzman

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

More from Medium

Player Jump in Unity

Creating Rewarded Video Ads in Unity

Creating a Simple Cooldown System In Unity

Adding a thruster speed boost on keypress