UnityCreating Coin Distraction Feature in Unity (Part 4: Make Guards Go Back to the Waypoints Path)

Objective: When guards reach the coin, make them wait some seconds and go back to their default path.

In part 3 we managed to make the guards move to the coin, but after that they just stay there the rest of the game. To add some realism we are going to make the guards wait some seconds and then go back to the waypoints path.

In the WayBeforeMove Coroutine I change the value of the isStopped property of the nav mesh agent to make sure the guard stops the movement and starts the movement again.

Then I declared a bool variable called _otherMovement, if this variable is true the guard stops following the waypoints path, check for the distance between its position and the new destination and if the distance is less than 1, we set the _otherMovement variable to false and start the coroutine WaitBeforeMove (the guard waits some seconds before go back to the waypoints path).

And that’s it!!! The guards just check the coin position for some seconds and they go back to their path.

--

--

--

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

Tuning proxy_buffer_size in nginx

Weeknotes: week 33

A plan of multiple activities, grouped by weeks, including content freeze and launch

AngelsCreed Weekly Report (February 21st to February 25th)

Finally, a Solution to Google App Engine’s Environment Variables

Docker Hub: The Choice for Better Business Outcome

Caching in Hibernate

Commutatus, a consulting development agency, manages over 50 applications with Cloud 66 across AWS…

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

Slick Orbital Camera Movements using Free Look Cameras

HitBox Attack System in Unity

Light her up — Adding emissions to your game objects using photoshop and blender

How to Create A Loading Scene in Unity