In the 2D and Turnbased examples, There are grid that walkable and obstacles that not. I am wonder if I can use not obstacles, but setting walkable direction in the grid?
You can set up Node links with oneway, though this can’t be automated. You either have to place these manually or write a script to place them for you.
If you’re using prefabs I suppose you could add one of these into your prefab to not have to worry about them
That sounds complicated. Maybe I should use recastgraph if the map is very huge. Can I set the agent to only walk along the integer position on a recastgraph? Like a fade grid.
Using walls just to constrain the directions which are walkable is not possible at the moment without a custom script. You can write such a script relatively easily though.
Something like
public LayerMask layerMask = -1;
void Start () {
// Update the graph when pathfinding has been paused
AstarPath.active.AddWorkItem(() => {
var gg = AstarPath.active.data.gridGraph;
// Iterate through alll nodes
gg.GetNodes(node => {
// Iterate through all neighbors of the node
for (int dir = 0; dir < 8; dir++) {
var neighbor = node.GetNeighbourAlongDirection(dir);
if (neighbor != null) {
// If there is an obstacle between them then disable the connection
if (Physics.Linecast((Vector3)node.position, (Vector3)neighbor.position, layerMask)) {
node.SetConnectionInternal(dir, false);
}
}
}
});
});
}
Make sure that the ground is not included in the layer mask.