I am trying to create a grid based turn based tactics game with a LayerdGrid.
Movement will be strictly centre of node to center of node (E.g. XCOM).
In the below image, the grey grid are the tiles, and the yellow lines are the node connections generated by A* which are in the center of each tile.
If there a way I can make a thin wall (white wall in the image) to block a node connection so the player cant move through it? I have indicated the connections I dont want with red arrows.
Currently Node size is 1, player diameter 1.
Blocking movement on grid graphs is primarily done by making nodes unwalkable, so doing what you are asking is not possible out of the box. Since you cannot increase the graph resolution to make the wall lie on a node, you would need to modify the grid graph a bit.
More specifically in the LayerGridGraphGenerator.cs script, inside the CalculateConnections method you would have to change this line (around line 815)
if (other != null && other.Walkable) {
To add a check for if it is possible to move from ‘node’ to ‘other’. Probably you want to use Physics.Linecast to do this something like
if (other != null && other.Walkable && Physics.Linecast((Vector3)node.position, (Vector3)other.position, /* ...layer masks and other settings */)) {
If I add the following code at line 811 (just above the line you suggest I change), it SHOULD do nothing at all, but I am getting an error when I click Scan. When I remove the linecast there are no problems.
You see the if statement below checks specifically for if ‘other’ is not null, but you are trying to access the position field of it before you have checked if it is null or not.