Support Forum

GetNearest return error NNInfo when I use more then one GridGrapj

I’m using more than one Grid Graph in one scene.
And I code like this

    for (int i = 0; i <; i++)
        var graph =[i] as GridGraph;
        if (
            GraphMask mask = GraphMask.FromGraph(graph);
            var nn = NNConstraint.Default;
            nn.walkable = true;
            nn.graphMask = mask;
            return, nn);

But the NNInfo returned included position like (-19505,-15400,0) (biiiiiiiig number), why? And thanks…


Not sure. How exactly are you reading the position?

Note that node.position is an Int3, not a Vector3. You can convert it to a Vector3 using (Vector3)nnInfo.node.position.

Sorry, I just recoded it.
Now I get a random grid node first,like the doc said (Wandering AI Tutorial)

// For grid graphs
randomNode = grid.nodes[Random.Range(0, grid.nodes.Length)];

and then use the GetNearest function like I said in the question with custom NNConstraint using GraphMask.Like:, nn);

And I still got a wrong answer ⊙︿⊙
Before I convert it , x or y value in node position is a minus,after I convert it still though


Why do you use GetNearest on a node position? You already have the node.

Sorry!!! MY FAULT!!! I forget to conver the world position to local position

Cause not all the nodes are avaliable now,so I wanna get a new node avaliable. Or is there a quickly way to find a random & walkable node?

And I found that once if I let about 10 characters wander togegher,it’s easily to get the positions nearby