Usage example
The following is an example of using the Path object to find the path from A to B.
using Nav3D.API;
using System;
using UnityEngine;
class YourGameScenario : MonoBehaviour
{
private void Start()
{
Nav3DManager.InitNav3D(1f);
Vector3 a = new Vector3(-10, 10, 10);
Vector3 b = new Vector3(-10, 10, 10);
FindPath(a, b, PrintPath);
}
//your method for pathfinding from A to B
void FindPath(Vector3 _A, Vector3 _B, Action<Vector3[]> _OnPathFound)
{
//create Path instance
Path path = Nav3DPathfindingManager.PrefetchPath(_A, _B);
//perform pathfinding from _A to _B
path.UpdatePath(_OnSuccess: () =>
{
//notify that path was found
UnityEngine.Debug.Log("Path successfully found!");
//invoke callback
_OnPathFound(path.Trajectory);
//finish work with Path instance
path.Dispose();
});
}
void PrintPath(Vector3[] _Path)
{
for (int i = 0; i < _Path.Length - 1; i++)
UnityEngine.Debug.LogError($"Path point {i}: {_Path[i]}");
}
}