Professional Documents
Culture Documents
Navmesh
Navmesh
org/twntduff/navmesh/src
NavMesh
The meshes that graphically display the navmesh object were created
in Blender and loaded in OBJ form. The same vertices and indices lists that
were created during this process are then used to create and connect the
triangle nodes that make up the eNavMesh object. Each triangle node has an
array of pointers that point to adjacent triangles for use in pathfinding, and a
pointer to a parent triangle that is later used to trace back through the
triangles which represent the optimal path, and G/H values that are used
during the A-Star algorithm.
A Star
The A-Star algorithm is used to determine the optimal path of triangles
to reach a goal point. Before the algorithm runs, it is first determined if it is
necessary to do so. If the start point and the goal point are contained in the
same triangle, then there is no point in using the A-Star algorithm to find an
optimal path and the only point that is needed in the path list is the goal
point. If either the start or the goal point is not contained within a triangle in
the navmesh, then we do nothing because the point is either unreachable or
the entity is located outside of the navmesh.
used in further iterations. The algorithm is completed when the goal triangle
is reached or the left and right array has reached the last item.
Changes in Y
If the project that the navmesh was being used in had no changes in
height from one edge to another, we could stop here and this would be
adequate enough for smooth pathfinding. If the project does require a
navmesh with changes in height, then we have one more step to ensure that
the path that is returned is correct and there are no anomalies. Some
anomalies that may occur is that the entity will go through the floor or hover
above the floor and not follow along the navmesh as it rises and falls. To
account for the changes in the Y direction, instead of returning the apex
array that contains the start, corners, and goal position, the path smoothing
algorithm takes this array and casts a 2D line (X, Z) from one apex to
another and uses the left and right vertices array to plot a point on the edges
that they frame. Once a 2D apex line no longer crosses with an edge, the
apex line is advanced to the next two apexes in the array. Once a point is
located on a line in the X and Z coordinates, it is then plotted on the 3D line
using the parametric equation of a line in 3D space to calculate the height of
which the point should lie at the X and Z coordinates.
3D Picking
The start point of the path is located at the current position of the
entity and the goal point is located at the point where the mouse is located
when the left mouse button is clicked. The 2D point where the mouse is
located when a left click input is received is projected onto the navmesh in
3D space. This is accomplished by casting a ray from the cameras location
towards a position in 3D space. If the ray intersects with a triangle on the
navmesh, the point of intersection is returned and used as the goal point for
pathfinding.
System Limitations
The way that the changes in Y is solved does not allow for edges to
pass under a potential apex line. Therefore, it is important to ensure that a
triangle node that might lie in the optimal path list does not run under a
current apex line when it is constructed. This means that there can be no
sharp turns that run under another turn on the mesh.