- Home /
Using GetNavMeshLayer to get layer at character location?
I'm trying to dynamically determine the NavMesh layer which the player is currently standing on. While GetNavMeshLayerByName returns the correct IDs for the layers I'm using (3, 4 and 5), GetNavMeshLayer itself only ever seems to return 0. I used it roughly like this:
navMeshLayer = GameObjectUtility.GetNavMeshLayer(agent);
with "navMeshLayer" being an integer and "agent" the NavMeshAgent/Player. At the moment this always returns 0 no matter which layer the player is on.
I've been helping myself with this workaround:
private NavMeshHit currentLayer;
for (int i = 0; i < 32; i++)
{
if (NavMesh.FindClosestEdge(player.transform.position, out currentLayer, (1 << i)))
{
objectLayer = i;
}
}
Debug.Log ("Object Layer" + objectLayer);
Obviously finding the closest edge quickly fails when layers overlap, which happens quite frequently with the way I generate the mesh. Am I misunderstanding what the method is supposed to do? There doesn't seem to be any documentation on it except for the cryptic sentence "Get the navmesh layer for the GameObject."
So I guess my question is: how to I determine which NavMesh layer by player (=NavMeshAgent) is standing on at any given time? Ideally I would also be able to detect multipe layers if the player happens to stand on a spot where they overlap.
Your answer
Follow this Question
Related Questions
How do I do AI pathfinding in a scene that changes drastically during play 0 Answers
Navmesh Path is shown even between disconnected regions.? 0 Answers
Not allow instantiate obstacle that make destination unreachable 0 Answers
Best way to handle finding a players path? 1 Answer
CalculateTriangulation is unacculate, is solution about unacculate of CalculateTriangulation 0 Answers