Usage example - Nav3D Doc

Docy Child

Usage example

Below presented an example of how to search for a path from A to B using Nav3DPath.

				
					using Nav3D.API;
using System;
using System.Linq;
using UnityEngine;

class YourGameScenario : MonoBehaviour
{
   #region Attributes

   Vector3[] m_FoundPath;

   #endregion
  
   #region Unity events

   void Start()
   {
       Nav3DManager.OnNav3DInit += () =>
       {
           Vector3 a = new Vector3(-10, -10, -10);
           Vector3 b = new Vector3(10, 10, 10);

           FindPath(a, b, PrintPath);
       };
   }

   void OnDrawGizmos()
   {
       if (!Application.isPlaying || !enabled)
           return;

       if (m_FoundPath != null && m_FoundPath.Any())
       {
           for (int i = 0; i < m_FoundPath.Length - 1; i++)
               Gizmos.DrawLine(m_FoundPath[i], m_FoundPath[i + 1]);
       }
   }
  
   #endregion

   #region Service methods

   //your method for pathfinding from A to B
   void FindPath(Vector3 _A, Vector3 _B, Action<Vector3[]> _OnPathFound)
   {
       //create Nav3DPathPath instance
       Nav3DPath path = new Nav3DPath(gameObject.name);

       //perform pathfinding from _A to _B
       path.Find(
               _A,
               _B,
               _OnSuccess: () =>
               {
                   //notify that path was found
                   Debug.Log("Path successfully found!");

                   //invoke callback
                   _OnPathFound(path.Trajectory);

                   //finish work with Nav3DPath instance
                   path.Dispose();
               }
           );
   }

   void PrintPath(Vector3[] _Path)
   {
       m_FoundPath = _Path;

       Debug.Log($"Path points: {string.Join(", ", m_FoundPath)}");
   }

   #endregion
}

				
			

Nav3DSphereShell

Represents a spherical shell that is perceived by other agents as an object to a...

Nav3DEvader

There is also a separate controller, whose behavior consists of just avoiding ne...

Nav3DAgentManager

This class implements several methods to get a list of all Nav3DAgents located i...

Nav3DPathTester

We implemented a useful component (Nav3DPathTester), which can be used while bui...

PathfindingResult

Contains the pathfinding data and time statistics. Time statistics: public TimeS...

Nav3DPath: Events

For the convenience of notification when the pathfinding finished, the following...

Agent log

Here you can copy the contents of the agent log to the clipboard by clicking the...

Debug drawing

In this section, you can visualize the agent and his nearest environment. This s...

Creating and configuring an agent description from code

All Nav3DAgentDescription parameters configured in the description inspector c...

Nav3DManager

Nav3DManager is a helper static class. Can be useful for checking whether Nav3D ...

Nav3DInitializer

To use Nav3D in playmode, you need to initialize it. The Nav3DInitializer compon...

Nav3DObstacleLoader

To use the possibility of pre-baking obstacles on the scene in editor mode and t...

Chat Icon Close Icon
en_USEnglish