Example of how to filter walkability of nodes in GridGraph?

HomeForumsA* Pathfinding ProjectSupportExample of how to filter walkability of nodes in GridGraph?

Tagged: 

This topic has 2 voices, contains 4 replies, and was last updated by  DeathByHugs 87 days ago.

Viewing 5 posts - 1 through 5 (of 5 total)
Author Posts
Author Posts
December 23, 2011 at 22:16 #1131

Learner

Could we get an example of how to filter nodes on GridGraph for things like walkability during the graph generation? For some of the issues I’ve been fighting, this would be useful. Maybe something like removing all nodes that can’t be reach from a certain point (to make rooftop & tree tops unwalkable, instead of walkable at a different height).

One issue I’m fighting is I don’t have direct control of my map and there are overhanging trees, lights, balconies, flat rooms narrow dividing walls (some only shoulder high) etc all built into the ground layer (not separate objects). So tuning the parameters for GridGraph is tricky and I don’t want to have to go around and flag all those areas manually as unwalkable..

December 25, 2011 at 00:20 #1139

Aron Granberg

Hm… something like this maybe:


//Using version 3.0.8
using Pathfinding; //at the top of script

GridGraph graph = AstarPath.active.astarData.gridGraph; //Shortcut to the first grid graph
Node startNode = AstarPath.active.GetNearest (somePosition); //The node to start from
//Loop through all nodes in the graph
for (int i=0;i if (graph.nodes[i].area != startNode.area) { //This node cannot be reached from the startNode
graph.nodes[i].walkable = false;
}
}
//Calculate all connections, this isn't really needed since the nodes are not reachable anyway, but why not.
for (int i=0;i GridGraph.CalculateConnections (graph.nodes[i] as GridNode);
}
//We are done

This should be called after scanning has been done.
See OnLatePostScan, which you can sign up to in Awake to get a callback when scanning has been done
public void Awake () {
AstarPath.OnLatePostScan += FilterWalkability; //Register to the callback
}
public void FilterWalkability (AstarPath script) {
//Walkability filtering here
AstarPath.OnLatePostScan -= FilterWalkability; //Unregister from the callback
}

Note: code written directly on page, not checked, but I think it should work

I hope it works for you!

January 4, 2012 at 00:03 #1230

Learner

Thanks, that was a big help once I corrected the for loop errors cause by the forums mangling.

February 21, 2012 at 19:55 #1544

DeathByHugs

Well with what i am working on the grid objects can be edited so when i am finished moving everything around i use this code to set the walkability. It work about 50% of the time depending on how i block off the path. I can move a block one unit to the side and then it will say that all the open node without objects on them can be reached even tho they are still blocked. I need it to work 100% of the time editing the objects in the area is a big part of the game and i need the AI to keep up with it.

February 21, 2012 at 20:57 #1545

DeathByHugs

Well I guess i posted this a little to early i fixed it by setting the Min area size to 1. Hopefully this helps someone else.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Example of how to filter walkability of nodes in GridGraph?
Your information:






<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>