Advertisement
Guest User

CaluclatePath without NavAgent

a guest
Feb 13th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. //----------------------------------------------------------------------------------------
  2. private static NavMeshPath CalculatePath(Vector3 _from, Vector3 _to, int _navigationLayer, int _agentType, int _areaMask)
  3. {
  4. var navMeshQueryFilter = new NavMeshQueryFilter();
  5. var navMeshPath = new NavMeshPath();
  6.  
  7. // also set area cost here if you have
  8. //m_navMeshQueryFilter.SetAreaCost(_layer, _costsForLayer);
  9. navMeshQueryFilter.agentTypeID = _agentType;
  10. navMeshQueryFilter.areaMask = _areaMask;
  11.  
  12. NavMeshHit hitStart, hitEnd;
  13. var ok = NavMesh.SamplePosition(_from, out hitStart, 10.0f, _navigationLayer);
  14. ok &= NavMesh.SamplePosition(_to, out hitEnd, 10.0f, _navigationLayer);
  15. if (ok == false)
  16. return null;
  17.  
  18. var reachable = NavMesh.CalculatePath(hitStart.position, hitEnd.position, m_navMeshQueryFilter, navMeshPath);
  19. if (reachable == false)
  20. return null;
  21.  
  22. return navMeshPath;
  23. }
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement