Getting Nodes Above/Right/Upper Right of a Node

Hi,

I am instantiating 2 node by 2 node objects. Before this instantiation I check if the node I am clicking nearest is walkable. However, it doesn’t check if the other nodes the object will cover are walkable. My current plan is to get the node above, to the right of, and to the upper right of the node I’m checking, and test if all of them are walkable before instantiation. If any of those nodes are not walkable then I don’t want to allow instantiation. However I am not sure how to get these nodes to check if they are walkable.

So what I mean is, when I click the red spot right now it checks if the node there is walkable. It is, so it makes an object in the red square. This overlaps with the object that’s already there though. So I want to first check the blue squared nodes first. (that sphere has a box collider). From cursory research it seems like I could somehow use GetNodeConnection and specify directions.

Hi

In the future the method GridNode.GetNeighbourAlongDirection(int) will exist as well as GridGraph.GetNodesInArea(Rect). However since those are not released yet, here is the implementation for GetNeighbourAlongDirection.

/** Adjacent grid node in the specified direction.
 * This will return null if the node does not have a connection to a node
 * in that direction.
 *
 * The dir parameter corresponds to directions in the grid as:
 * \code
 *         Z
 *         |
 *         |
 *
 *      6  2  5
 *       \ | /
 * --  3 - X - 1  ----- X
 *       / | \
 *      7  0  4
 *
 *         |
 *         |
 * \endcode
 *
 * \see GetConnections
 */
public GridNode GetNeighbourAlongDirection (int direction) {
	if (GetConnectionInternal(direction)) {
		GridGraph gg = GetGridGraph(GraphIndex);
		return gg.nodes[NodeInGridIndex+gg.neighbourOffsets[direction]];
	}
	return null;
}

I think you should be able to add this to the GridNode class to get this functionality.

1 Like