Access to unwalkable nodes

Hi Aron,

I’ve been mulling this one over for awhile now, and I have come to the conclusion that it would be really helpful if when grabbing nodes, or calling something like constructPath on a ConstPath, if we could pass a flag to return unwalkable nodes. In my original game using your engine, we ended up creating an entirely separate grid that was layered on top of your grid, so that we could properly traverse the tiles (nodes) and see who was standing where, and get proper paths. Like we both discussed from a previous post, when I tried to get a path to a character who had blocked a node, your pathfinding system returns the wrong node. The only way around it was to temporarily re-enable the node, grab the path - 1 nodes, then re-disable the node. The whole thing just seems unnecessary. Let me know what you think.

Hi

Maybe you want to use tagging?
See http://arongranberg.com/astar/docs/tags.php

No, I went down this path and it turned out to be a big mistake (as you and I discussed in a previous thread). Tagging would be a good solution with a bitshifted tag, but not with the tag in its current state.

Ok.

So you are requesting a path which ignores all unwalkable nodes.
I am not sure how useful that would be since it would just be a straight line essentially (or with at most one corner since grid graphs do not allow straight lines in all directions).

Ok, that’s a good point :wink: let me clear it up

Let’s think about this like a chess board, where we have an 8x8 grid, and each square that a piece is standing on, is unwalkable.

Scenario 1: I have a hero who is X squares away, and he needs to path to an enemy.
Current Solution: Find the enemy who is the target, make his node walkable. Call StartPath, grab the array of path nodes, and remove the last node from the array. Make enemy node unwalkable again. You now have the best path.
Suggested Solution: Create a new override StartPath function such as: Call StartPath(startpos, endpos, endPosWalkable = true), where the endpos given finds the nearest node, regardless of wether or not it is walkable, and paths to that node. All other unwalkable nodes are still accounted for in the pathing system.

Scenario 2: I have a hero, it is his turn, I want to highlight all the tiles that he can reach that are 3 squares away. I also want to highlight enemy tiles that can be reached a different color, interactive items (like a chest) a different color, etc.
Current Solution: Maintain my own grid, that is a 1:1 grid with the existing gridgraph. Do an outward search from my own maintained grid, grabbing all tiles up to 3 squares away. Then search each tile to see if there is an entity, chest, or some kind of blocker (ie a wall). Highlight the tiles as I go along.
Suggested Solution: A little more complex.
First, it would be great if we extended GridGraph all together, so that the transform that sets a node to unwalkable is stored in the GridGraph. It would be a member in GridNode.
Second, an override function for ConstantGraph.Construct(), that returns only unwalkable nodes, so that you can easily scan them and see what is there. (Like an entity, chest, wall, etc).

Let me know what you think.

Hi

I think the best solution for you would be to override the Path.CanTraverse method and put all the code you need there. Then you can use your own internal state of where all characters are and feed that to the paths. The rest of the graph would be completely walkable (unless you have some other walls or something that you want to be unwalkable in all cases).

The CanTraverse method is not virtual by default (for performance reasons, it is called A LOT) but you can just make it virtual.