Character Movement with Unity NavMesh

While I enjoy first person combat shooters, a fair share of flight and space simulators and looking forward to getting to a new level of immersive experience with VR — I am just as hopeful for tabletop strategy mixed reality, holographic apps sci-fi pitched from Episode IV to mobile game ads today.

A usual component for strategy games is pathfinding for some controllable in-game elements on terrain or structures; fortunately, Unity has built-in capability for navigation and pathfinding discussed in http://docs.unity3d.com/Manual/Navigation.html.

I’ll cover the setup from creating the structure to scripting the character controls using a similar structure used as an example in the Unity documentation.

Nav-Structure

The end result is a multi-level structure with ramps, a gate system and character that moves around the structure based on a point-and-click to the destination.

Creating the structure

I use Autodesk Maya for 3D work, the general idea and approach is similar across 3D tools.
The setup is straightforward, start with a cube with depth = 20, width = 20 and height = 1.

I setup the grid snapping every 1 unit and enable subdivisions = 10 when I need to work on thinner components.

Nav-Maya3

The most direct way is cut faces at grid positions approximating the structure and extruding polygons.

Nav-Maya4

The structure is relatively simple, requiring just a few vertices.

If you just want something fast to test and not really concerned with vertex count, the quick and dirty approach is to start with the same (20 x 20 x 1) cube and setup (20 x 20 x 1) subdivisions; this brings us back to Lego (or Minecraft) creation strategies of extruding up the blocks we need for the second level and cutting edges to extrude the bridge components.

Nav-Maya5

The end result is a multi-level structure we can use to try out pathfinding in Unity. You can refer to my import notes in Creating Virtual and Mixed Reality Apps using Unity, Visual Studio and Azure

For questions, comments or contact – Twitter @rlozada