Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------------------------------------------------------------------------------
- private static NavMeshPath CalculatePath(Vector3 _from, Vector3 _to, int _navigationLayer, int _agentType, int _areaMask)
- {
- var navMeshQueryFilter = new NavMeshQueryFilter();
- var navMeshPath = new NavMeshPath();
- // also set area cost here if you have
- //m_navMeshQueryFilter.SetAreaCost(_layer, _costsForLayer);
- navMeshQueryFilter.agentTypeID = _agentType;
- navMeshQueryFilter.areaMask = _areaMask;
- NavMeshHit hitStart, hitEnd;
- var ok = NavMesh.SamplePosition(_from, out hitStart, 10.0f, _navigationLayer);
- ok &= NavMesh.SamplePosition(_to, out hitEnd, 10.0f, _navigationLayer);
- if (ok == false)
- return null;
- var reachable = NavMesh.CalculatePath(hitStart.position, hitEnd.position, m_navMeshQueryFilter, navMeshPath);
- if (reachable == false)
- return null;
- return navMeshPath;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement