If you’re using a tilemap, it’s easy. This is the flood fill I use to check for closed-off areas in a procedural dungeon. I wouldn’t use recursion, as it’s a pretty simple algorithm anyway:
var looked = {}
var q = []
var curr = Vector2(0, 0)
# Pick a random, walkable point.
while not G.WALK[G.map_tiles.get_cellv(curr)]:
curr = Vector2(randi() % MAP_SIZE_X, randi() % MAP_SIZE_Y)
q.push_back(curr)
while not q.empty():
curr = q.pop_front()
looked[curr] = true
for dy in 3:
for dx in 3:
var l = Vector2(curr.x + dx - 1, curr.y + dy - 1)
if (not looked.has(l)) and G.WALK[G.map_tiles.get_cellv(l)]:
looked[l] = true
q.push_back(l)
Not tilemap. I want use it for 3d too in future.
Robotex | 2020-09-06 20:44
I guess you could divide up the volume into a grid, about as large as an obstacle, and cache all the locations in an array – then use the same algorithm. Or you could make a node with an area node attached and move it through the volume in basically the same way, using the area to detect collisions with the obstacles – but that might be slower.
duane | 2020-09-06 22:26
How to detect collisions of point with obstacles?
Robotex | 2020-09-07 09:46
Looks like, Physics2DDirectSpaceState.intersect_point may help
Just get the state from the world and do the queries.