# The Quest for a smart influence map

I’ve been working on an Influence Map system for my swarming AI positioning around the player. Where AStar comes in to this equation is when I’m looking at making sure a spot on said influence map is actually reachable.

What I’ve ended up making is a system to check whether a point on my influence map is close to a point on the navmesh. This actually works really well, but it’s pretty damn slow for such a simple function.

Asking for wisdom on any better way to do this, or if it’s at all possible to find a faster method than PointOnNavmesh.

Code snippet below. Grid is 10 by 10.

private void NavTest()
{
if(influenceMap!= null)
{
for(int i = 0; i < gridSize; i++)
{
for(int j = 0; j < gridSize; j++)
{
Vector3 inputPosition = GridToWorld(new Vector2(i, j));
GraphNode testPosition = AstarPath.active.data.recastGraph.PointOnNavmesh(inputPosition, NNConstraint.None);
if(testPosition == null)
{
influenceMap[i, j].IsValid = false;
}
else
{
var v3 = (Vector3)testPosition.position;
float distance = v3.y - inputPosition.y;
if(distance > 2 || distance < -2)
{
influenceMap[i, j].IsValid = false;
}
else
{
influenceMap[i, j].IsValid = true;
}

``````                }
}
}
}
}
``````

Hi

For your use case I would recommend that you cache the last node that PointOnNavmesh returned (cast it to TriangleMeshNode). Then when you check the next point, you can test if that node contains the point using TriangleMeshNode.ContainsPoint. This should be much faster than using PointOnNavmesh. If the previous node did not contain the new point, you can fall back to PointOnNavmesh.