Show where a unit can move to in a turn based game

Hello! I’m using a GridGraph to map walkable nodes in a game that has a flat 2D tile map. I’m manually turning nodes on an off using a custom GraphUpdateObject. That’s all great so far.

Each unit will have a set amount of squares they can move and I’d like to be able to work out which tiles they can move to and maybe also how far that tile is. Can this be done with this framework? I had an idea of creating another GridGraph the size and position I need around the unit but that will still leave me with the same information.

Any ideas about how this framework can help me achieve this will be great as I’d prefer not to do it manually (mostly because it’ll probably be slow).

Thanks,
Farran

Hi

That can be solved using a ConstantPath request.
If you have the pro version, take a look at the PathTypes demo scene and look at the ConstantPath option, that shows all node within some distance from the specified node.

Using the free version (or the pro version) you can use this API: http://arongranberg.com/astar/docs/class_pathfinding_1_1_path_utilities.php#a9be5af0e79b81927648f7677c29d9833
However in the current release I think the implementation is bugged. Search the forum, there is a post about it which includes a fix.

Thanks for the reply. At the moment, using the free version, I’ve gone with a system where the unit creates paths to all the points until they’re all found. This seems to work well in keeping the game running fluidly and I handle the fact that it doesn’t happen instantly. The trouble with this method is that it works slowly if you have V-sync turned on as it limits the frames. If I upgrade to the Pro version I think I will look at the Seeker.StartMultiTargetPath() function and the ConstantPath (as you mentioned).

Thanks, Mr G!

Hi

Well, ok, that works… it is very brute force… but it works.
You can request multiple paths in the same frame if you bypass the seeker and use the AstarPath.StartPath method directly.

Aron,

since you hinted (very vaguely) that my approach wasn’t very good I decided to try the BFS approach. Okay, so it is a tad faster! I grabbed the updated code from this forum post:

Which almost worked but I found there was slightly off as it was processing a single out of range node before quitting the loop. The one line fix is shown below:

`while (que.Count > 0 && currentDist < depth ) {
	GraphNode n = que.Dequeue ();
	currentDist = map[n];

	if (currentDist < depth) // <--- Otherwise an out of range node will be added
		n.GetConnections (callback);
}`

As you’re helping me I thought I’d return the favour. Enjoy your weekend!

Sorry to dig this old thread out, but how did you manage to show the valid tiles / nodes in-game?