Hey, so I’m trying to use the “Flood Fill Method” to check if a player built room is enclosed. I’m a little lost with how I’d go about making this and I’m only just grasping how this method works. If someone would be able to point me in the right direction, or just fully explain this method it would be incredibly helpful, and I’d be very appreciative.
That takes a lot of math and dedication in understanding the Lua language, I suggest learning more on Lua before trying to create something like that. (Get a more general understanding of Lua). Since it uses a lot of math and coding, like a lot… I will not post it therefore I’m sorry I cannot help you, however please understand though that this is ROBLOX and is pretty difficult to code things such as that.
I’ve got a good understanding of Luau, just not with this kind of method.
It doesn’t seem to be as much code as you’re suggesting, based on what I’ve been reading up about. I’m only looking to see if a room has walls that enclose it.
When looking around I was able to find something like what I’m looking to do, I just need help understanding it and how I can manipulate it.
His Code,
local grid = {}
for x = 1, 15 do
grid[x] = {}
for y = 1, 15 do
local z = math.noise(x / 5, y / 5) < 1/5 and 0 or 1
print(z)
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.CFrame = CFrame.new(x, y, 0)
part.Color = Color3.new(z, 0, 0)
part.Parent = workspace
grid[x][y] = {
part = part,
flood = false,
z = z
}
end
end
local function flood(grid, x, y)
if grid[x][y].flood then return end
grid[x][y].flood = true
grid[x][y].part.Color = Color3.new(0, 1, 0)
wait(1 / 30)
grid[x][y].part.Color = Color3.new(0, 0, 1)
if grid[x - 1] and grid[x - 1][y].z == 0 then
flood(grid, x - 1, y)
end
if grid[x + 1] and grid[x + 1][y].z == 0 then
flood(grid, x + 1, y)
end
if grid[x][y - 1] and grid[x][y - 1].z == 0 then
flood(grid, x, y - 1)
end
if grid[x][y + 1] and grid[x][y + 1].z == 0 then
flood(grid, x, y + 1)
end
end
wait(1)
flood(grid, 1, 1)
This was taken from, How to implement the Flood Fill Algorithm, for Room Detection?! - #4 by DrKittyWaffles.
I just need help understanding it fully and how to manipulate it to my needs.
So from his code I can see that it starts at a point, recurses through all its neighbours and checks their neighbours, flood filling along the way
Yes, and now I just need help on how I use this on a horizontal plane and fill up a room to see if it is enclosed entirely.
Is C-frame what you would be looking for? Elaborate on what you need please.
There’s not anything I can “elaborate” on. I’ve got some walls and I need to know if it makes an enclosed space. Edit: I’m pretty sure I could do this but I just need 1 more thing; I need to know how to determine if there’s a part in a Vector3 position.
Basically, you need to get the size of the room. Then, use an if statement like this:
local FloodWater = game.Workspace.FloodWater
if FloodWater.Size = size_of_the_room_here then
(continue the code here)
else
print(“Flood Not Complete.”)
(continue if not code here)
end
Now from my understanding, this is what would be the best to use. If otherwise, I hope you find your solution! (:
You might have misunderstood… I’m talking about the Flood Fill Method… not water.
A flood system I think would be more for something thats not this
I would personally recommend using a voxel system or some kind of grid system (which is fairly limiting) to see if theres an enclosed room
Hmm, alright. I had just looked up “Room Detection” and just about every topic suggested using a Flood Fill Algorithm.