after finding an unconnected cave you could use a similar algorithm to the a-start path finding algorithm, this could give you a series of points to another cave that you use to generate the cave connecting them together
Your suggestion is very vague, could you care to elaborate?
Like for example, what do you mean by a “similar algorithm to the a-start path finding algorithm”
How would this give me a “series of points to another cave” ?
I recall that the YouTube Sebastian Lague has a video series about cave generation with cellular automata. He faced the same problem where he would like the caves to connect to each other.
I was thinking of flood-filling each different room, finding the centre of these regions and then using random walks to open up paths between these regions.
However, how would I use flood-fill to find and distinguish different regions of my cave, like so:
not a genius but could you loop through all the created caves, then check to see if its connected to another other cave, if not draw that new cave hallway to fit the distance needed to connect to the closets one
You went through exactly all of the logic behind it and none of the maths.
The problem I have with this is all the maths that needs to be done. Taking just one example in your suggestion, how would the script recognize a cave in the first place?
local function Flood(x,y)
if not Grid[x][y].flood and not Grid[x][y].Alive then
Grid[x][y].flood = true
Grid[x][y].Part.Color = Color3.new(0, 1, 0)
wait(1 / 10)
Grid[x][y].Part.Color = Color3.new(1, 0, 0)
if x < #Grid[1] then
coroutine.wrap(Flood)(x+1, y)
end
if x > 1 then
coroutine.wrap(Flood)(x-1, y)
end
if y < #Grid then
coroutine.wrap(Flood)(x, y+1)
end
if y > 1 then
coroutine.wrap(Flood)(x, y-1)
end
if x < #Grid[1] and y > 1 then
coroutine.wrap(Flood)(x+1, y-1)
end
if x > 1 and y > 1 then
coroutine.wrap(Flood)(x-1, y-1)
end
if x < #Grid[1] and y < #Grid then
coroutine.wrap(Flood)(x+1, y+1)
end
if x > 1 and y < #Grid then
coroutine.wrap(Flood)(x-1, y+1)
end
end
end
I think the problem has to do with how I’m calling the starting cell position. In theory, I want the script to loop through all points in my array until it finds an open cell, then it would call the flood fill function once and break off the loop.
However, the loop still seems to continue after the first open cell was found.
for x=1, SizeX do
for y=1, SizeY do
if not Grid[x][y].Alive then
-- Cell is dead, therefore open
Flood(x,y)
break
end
end
end