finding distance from a group of blocks

Godot Version: 4.1


I’m making a game about bees, and I’m trying to make it so that you can only travel up to 2 tiles away the hive (the yellow tiles).

Basically, i’m trying to find a way so that if you try to send a bee to a tile, it will check if that tile is within 2 spaces of the hive.
The main problem I’m facing is that while I can easily find a way to check the distance between 2 specific tiles, I need to see if the distance from one tile is within 2 from any of the hive spaces.

I had the idea that I could just make an invisible circular node at each tile, and group them so that the hive tiles would have some tag, so that way I’d just check for a collision between the tile you’re trying to travel to and a hive tile, but that feels needlessly complicated and cluttered.

Create a simple “distance grid” on your cell layout with a BFS (Breadth First Search) to populate each cell with its distance to “bee hives”.

You place your bee hives and mark every neighbor cell that is not a bee hive as 1.

The neighbors of that cells that are not already marked get a 2 … and … you see the pattern.

That way with a simple cell look up you know how far away from a bee hive everything is.