Using Tile Edges to Calculate Paths

Hi Aron,

I’m making a level with many destructible obstacles (walls), arranged on a tile grid. Our AI programmer is using AStar’s Grid Graph for pathfinding. We currently have to compromise on a grid size that is small enough to recognize doorways/openings, but not too small because it affects performance. The end result is not ideal.

We want to place walls on tile edges, keeping the grid-to-tile ratio 1:1. An “unwalkable” tile is blocked in all four cardinal directions. A wall blocks any given tile in one cardinal direction.

Our map editor draws walls on the seams between map tiles. Each tile keeps track of which sides are blocked by a wall with an array (e.g. tile.isBlockedNESW[true, true, false, false]). When a wall is destroyed, the tile updates which sides are blocked.

We want to connect this to AStar’s Pathfinding. In theory, we would check a neighbor tile’s isBlockedNESW array (instead of the tile itself) to determine if the AI’s path can travel in a given direction.

As you are the creator of this awesome AStar asset, I would love to get your perspective:

  1. Is what we’re trying to do completely crazy?
  2. If not, how could we get AStar working with our project?
  3. Do you have any other input?

Much appreciated,

  • Marcus
1 Like

Hi

This is possible, but not out of the box.
I would suggest that you create a subclass of the GridGraph and override the IsValidConnection method.

You would also need to create a small editor script for the graph to show up in the list of graphs.

using UnityEditor;
using Pathfinding;

[CustomGraphEditor(typeof(CustomGridGraph), "Custom Grid Graph")]
public class CustomGridGeneratorEditor : GridGraphEditor {
}

See also https://arongranberg.com/astar/docs/gridgraph.html#IsValidConnection