Grid Graph: Walkable from direction?

Hi

This is possible with a bit of code.

AstarPath.active.AddWorkItem(new AstarWorkItem(ctx => {
    var node1 = AstarPath.active.GetNearest(position1).node as GridNode;
    var node2 = AstarPath.active.GetNearest(position2).node as GridNode;
    // Remove the grid connection from node1 to node2
    for (int i = 0; i < 8; i++) {
        if (node1.GetNeighbourAlongDirection(i) == node2) {
             node1.SetConnectionInternal(i, false);
             break;
        }
    }

    // Required to update some metadata after all node connections have been changed
    ctx.QueueFloodFill();
}));

You may also have to use the latest beta, I think it might be possible for earlier versions to assume grid connections are bidirectional.

Also. This will only work if there is a possible path from D to C, but perhaps it is longer. Otherwise a part of the system that tries to calculate which nodes are reachable from which other nodes may get confused. If this is the case for you I can show you how to disable that (it’s just a 1 line code change).

See also X-com 2 style graph. Allow for thin walls (for a layered grid graph)