How to display A* path on gridmap

Godot Version



I’m not sure whether to put this under Shaders or Programming. I have the A* path working and store it as a Vector3 array. I also have a shader working. However, I’m not sure how to combine the two. I can get the shader to work on every instance of the cell in the mesh library, but I need it to select specific cells.
My first thought was to add a shader to the entire GridMap and set the vertices from the array, but I can’t see a shader as an option in the inspector. So, I’m quite stuck at the moment. My other idea was to try and disable the shader on the cell if it wasn’t in the array, but I can’t seem to get this to work. It disables it for all of them (which makes sense).

I haven’t worked with A* in 3d any, but in A* 2D, you can always draw a path with the path2d node.

Alternatively, I would fetch the array of points returned by the A* node’s get_id_path, and then use _draw() calls to draw lines between each node in the path.

Again, i don’t know how this is in 3D, but I imagine there is a related way to do this.

I could see this working, but I wanted a more visually appealing approach. However this did give me an idea of an easy solution (I hope it is anyways). Since everything is the same size cube, I could just overlay a pre-rendered sprite at the location of each cell.

Ah, yeah I thought this was for debugging, but if you are looking for something nice, what I did for my tactics game to show movement ranges was to just draw a tile at the locations I want to show.

So yeah, very similar idea here, just with rendering a sprite, you’ll just need all the locations between the two points, and boom!

1 Like