Skip to content

antzGames/Godot-A-Star-Pathfinding-for-Gridmaps

Repository files navigation

Godot A* Pathfinding for Gridmaps Plugin

An extended version of Godot's GridMap node that adds A* pathfinding support and in editor visual pathfinding debugging.

Now implemented as a plugin.

The old tuortial video is still here: https://youtu.be/t4-R5tmFakw

I may create an updated video.

This solution is great for 3D Dungeon Crawler games where you need to do pathfinding in discrete amounts in a grid pattern.

Limitations

  • All GridMap tile sizes in its MeshLibrary have to be the same size.
  • Hexagon tiles not supported.

How to install as a plugin

Add grid_map_pathfinding folder to your addons directory as shown below:

Using the new GridMapPathFinding node

Plugin's inspector changes

Path Cell Size

Not to be confused with GridMap.cell_size. So because the mesh cell size of KayKit and Kenney 3D tile asset packs may differ, and even within asset packs they may have different mesh sizes (like small, medium, large versions of tiles) you have to be very careful in setting the GridMap cell_size and this plugin's path_cell_size.

Finding out the correct path_cell_size and GridMap cell_size might take some investigation. But once figured out you do not have to worry about it again.

The best advice I can give you is when drawing cells in your GridMap, make sure they do not overlap. This will result in you skipping a grid tile. This means you will need to adjust the path_cell_size to value higher than 1.

The reason behind this is beyond the scope of this plugin's documentation.

Also, as previously documented in the Limitations section, all your tiles have to be the same size.

Walkable Items Array

This is an array of item_ids (from your GridMap's MeshLibrary) that you want to be walkable, which means that take part in pathfinding.

You do not have to edit this field directly, as the new Dock (described below) will allow you to add item_ids visually.

Custom dock

When GridMap is selection mode (arrow icon), then a single selected grid cell will update the custom dock called GridMapPathFindingDock.

Scenario 1: Selected cell NOT in the walkable_items array

When the selected cell in the grid map is NOT in the walkable_items array, which is going to be the case in a new project, you will see this in the dock:

You can click Add Item ID to Walkable Items button to add thsi item id (tile type) to the walkable_items array.

You can click Add to Start Cell button to assign the debug start cell to this grid position. You can click Add to End Cell button to assign the debug end cell to this grid position.

Scenario 2: Selected cell already in the walkable_items array

When the selected cell in the grid map is in the walkable_items array, you will see this:

You can click Add to Start Cell button to assign the debug start cell to this grid position. You can click Add to End Cell button to assign the debug end cell to this grid position.

Scenario 3: Selected cell not assigned a tile

When the selected cell does not have any assigned tile, then you will see this:

Optional in editor pathfinding debug

GridMap location to world space and vice versa

Remember, GridMap co-ordinate system is not the same as the world space. This is the one of the uses of my custom dock. However, in your code you can get this information by using the two following methods.

To convert GridMap locations to world space with:

grid_map.map_to_local(map_position: Vector3i) -> Vector3

To convert world locations to GridMap locations with:

grid_map.local_to_map(local_position: Vector3) -> Vector3i

See https://docs.godotengine.org/en/stable/classes/class_gridmap.html for more information.

Game Jam Example

I used this solution in my Dungeon Crawler Game Jam 2025 entry: https://antzgames.itch.io/dungeon-heist

About

An easy A* pathfinding plugin (addon) for Godot's GridMap.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published