I am creating building system similar to bloxburg’s one, however I have no idea how to deal with room detection system. It could be used for automatic floor placement or light switch and lamp connection.
It should work like this:
1 - function receives and array of smaller arrays containing end positions of walls,
2 - function analyzes which areas are surrounded by walls,
3 - function returns several arrays containing ordered corners of rooms.
I am very inexperienced so this is probably useless but maybe try making a table with each wall corner having a part and then put all the connected parts in it aswell and then find common ones in them all so you find the room. E.g. there is a room connected by the corners at 1,4. 2,9. 6,9. 6,6. You would make a table E.g.
local points = {
A = {
Cords = 1.4
Connected = {
A = 2,9
B = 6,6
}
}
}
I barely know Lua so that code wont work because formatting and spelling but yo get the idea. Then you try run through them all till you find a group of connected points. Then you would probably find the center point of it and find where the mouse was pointing and pick whichever room is closest or use extra maths to find which rooms it is in by the cordinates of it.
This is probably not going to work but nobody else seems to be able to help so i have tried my best
Creating a room detection system similar to Bloxburg’s building system involves a few key steps. While I won’t provide a full code implementation, I can outline the approach you can take to achieve this functionality in Roblox:
Input Data Structure:
Define a structure to represent the walls. This could be an array of smaller arrays where each smaller array contains the end positions of a wall (e.g., {{position1, position2}, {position3, position4}, ...}).
Grid Representation:
Create a grid-based representation of your building area. This grid should match the size of your building area and be divided into cells. The size of the cells depends on your requirements; they could be large for general room detection or smaller for finer-grained detail.
Wall Detection:
For each wall segment in your input data, iterate through the grid cells it intersects and mark those cells as “wall” cells.
Flood Fill Algorithm:
Implement a flood fill algorithm to identify enclosed areas. This algorithm starts from a cell and recursively explores adjacent cells, marking them as part of the same room. As you traverse the grid, you’ll identify rooms by grouping cells together.
Room Detection:
As you apply the flood fill algorithm, store the cells belonging to each room in separate arrays.
Output:
Return the ordered corners of the rooms as you’ve described.
Here’s a high-level description of how you can implement these steps:
Start by creating a grid that represents your building area. Each cell in the grid corresponds to a specific position in your building area.
Iterate through the wall segments and mark the appropriate cells in the grid as “wall” cells.
Implement a flood fill algorithm that traverses the grid. Start from an unvisited cell, explore all connected unvisited cells, and mark them as visited. Keep track of the cells belonging to each room as you go.
Once you’ve finished traversing the grid, you will have identified rooms and their respective cells.
For each room, determine the ordered corners by finding the minimum and maximum x and z coordinates of the cells it contains.
Remember that this is a simplified overview, and the actual implementation may require more detailed considerations based on your game’s specific requirements. You may also need to handle corner cases and optimizations depending on your use case.
It’s a complex system, but breaking it down into smaller steps and thoroughly testing each step as you go will help you build a functional room detection system for your game.