Visual representation of grid and paths

Hello, I am just beginning to use this great library, sorry if the question is silly.

The game I’m building is turn-based and all characters position exactly to nodes(think of a chessboard). I need to display a visual representation of the Grid, as well as click detection on each “cell” of the grid. Is there a built-in way to achieve this visible grid, or can I somehow retrieve the position of all the nodes, to generate a visible “square” on top of them?

I imagine most strategy games require clickable grid cells, so there must be a way.

Thanks for your help.

Hey David welcome to the forum!

I would suggest looking at the simplest scenario point graph(ExampleScenes/Example5_PointGraph)
You can duplicate this scene or copy paste the A* gameobject into your own and then play around with the green cubes.
Then arrange them how you want maybe add colliders to the so you can click them.

You can have a look at the ‘Player’ gameobjects with the seeker/aiPath/AiDestination scripts to see how it gets paths and so forth.

A great starting place to explore! :slight_smile:

The visualization of grids is usually very different from game to game. In the example scene called ‘turnbased’ one way is used for a hexagonal graph in which a prefab is instantiated for each node that a character can walk to.

Thanks, I figured it out and did it, it was real easy once I found out how to access the nodes data. In case another beginner stumbles into this, this is how I did it (basecell is my cell prefab):

    List<GraphNode>nodes=PathUtilities.BFS(playerNode, size);
    foreach (GraphNode node in nodes)
        if (node.Walkable) {
            GameObject cell = (GameObject)Instantiate(basecell);               
            cell.transform.position = (Vector3)node.position;;
        }
1 Like