top of page

Navigation in Unity

Writer's picture: Manogane SydwellManogane Sydwell

Updated: Oct 8, 2020

In this article we will discuss, and implement some of Unity’s features. In particular, we will be discussion how navigation plays a role in a game of hide and seek. As a game engine, Unity has as great number of possible use cases, from education to entertainment. Beyond the fact that one can make PlayStation and Xbox games with Unity, it's really fun to tinker with. Let us begin!


Synopsis

In the scenario presented below, we create a situation in which a robber must flee the pursuit of a cop in a simulated environment. Before discussing anything else, we must discuss important terminology for this article.




A. Polygon Mesh

A polygon mesh is a collection of vertices, edges and faces that make up a 3D object. A polygon mesh describes the shape of a 3D object, whether it is used in a video game like The Sims, or an animated movie like Spider-Man: Into the Spider-Verse.




The scene(Cops and Robbers) shown above is a combination of meshes. The house is a mesh and so are the trees and characters.  A very good and brief introductory article on polygon meshes can be found here


B. The NavMesh

The Navigation Mesh(or NavMesh for short) is an abstract data structure used in several artificial intelligence applications to guide agents into finding paths from one point to another, within a particular environment. 

The NavMesh guides Non-Playable Characters to move within the confines of the defined environment without going through houses and other solid objects, as is shown by the cop and robber scene. The NavMesh will be discussed in more detail later on in the article.


Failure to act within the confines of the environment was common to sixth generation gaming consoles like the PlayStation 2. If you ever played Lara Craft or Grand Theft Auto on the PS2, then I know you can relate.To summarize, the NavMesh makes navigating a game environment possible in a realistic manner.


C. Agent

An agent can be defined as an entity which is capable of completing activities by itself. In the scenarios presented above, this would be the robber. 


NavMeshAgent in Detail


There's a lot of things going on in the scene show above, as much as it has been simplified from the first scene in this article. In order to have this article deliver value to those who read it, we will focus specifically on the NavMeshAgent. Just to clarify:

  1. The cop is not a NavMeshAgent. We are able to control his movements through the keyboard or a joystick if you wish to do so.

  2. The Tree is an obstacle in the scene shown above.

  3. In order to turn the Robber into a NavMeshAgent, we must add this component to the robber in the Inspector, as can be seen in the screen shot below.



Now to discuss the NavMeshAgent. For ease of readability and clarity, the following will be in point form

  • In order to see the NavMesh, we select the tree and the ground plane. In the Inspector, we see that these two objects are marked as Navigation Static.


  • To enable the robber[the NavMeshAgent] to navigate the ground plane while treating the tree as an obstacle, we "Bake" these objects in the Navigation Window.


  • And that's it. Marking these objects as Navigation Static and thereafter Baking them is what enables the Robber to navigate this environment, holding all other inputs constant.

Another thing omitted for the sake of brevity would be the C# code that enables the robber to move. This will be discussed in future articles.



Managing Emotional Oscillations that Come with Unity

As great as it is developing video games and simple scenes like the ones described above, being creative with game development engines like Unity can be a pain at times. I have no better illustration than with a course I’m currently doing via learn.unity, which is now free in perpetuity. 




In the scene above, we can see shells being dropped on a tank. This is supposed reduce the health of the tank, or maybe make it explode. But even after all shells fall on the tank, there’s no effect on its health.  And that’s the pain! Sometimes objects do not behave as I want them to. Because this is programming, I have no one else to blame for scenes like the one illustrated above but myself. And when things don’t work, it usually entails redoing the project from scratch. 




However difficult this may be, I am very much aware that this is part of learning Unity. Making mistakes is part of learning just like with mathematics, sports, social interactions and so on. More than the mistakes however, is the realization that mistakes are lessons. Without mistakes, I would not be able to make progress. So as much as I’m annoyed by the Indestructible Tank shown above, I am grateful for the lesson it has taught me. Complement this video by checking out virtual reality projects that can be made with Unity.




References

Unity for Playstation 4 is here, blogs.unity3d.com

Microsoft Creators Program, unity3d.com

What is a Polygon Mesh, conceptartempire.com

Abstract Data Types, geeksforgeeks.org

Unity--NavMesh Tutorial(EN), medium.com

Why The 6th Console Generation Was The Golden Age Of Gaming, youtube.com

66 views0 comments

Recent Posts

See All

Comments


©2020 by creativeAfricanProjects.

bottom of page