- Home /
Detecting procedural generation overlap
I've been following this tutorial on procedurally generating game levels through premade game objects, and it's been one of the more helpful tutorials I've found for procedural generation. However, the algorithm has one big problem: it has no way to detect if the section it will spawn will overlap an existing section. This is the section of code where it spawns the next section of level.
for (int iteration = 0; iteration < Iterations; iteration++)
{
var newExits = new List<ModuleConnector>();
foreach (var pendingExit in pendingExits)
{
//generate suitable exits
var newTag = GetRandom(pendingExit.Tags);
var newModulePrefab = GetRandomWithTag(Modules, newTag);
//spawn the next room
var newModule = (Module) Instantiate(newModulePrefab);
var newModuleExits = newModule.GetExits();
//rotate and position it to match the existing room
//get all new exits after this round of generation
var exitToMatch = newModuleExits.FirstOrDefault(x => x.IsDefault) ?? GetRandom(newModuleExits);
MatchExits(pendingExit, exitToMatch);
newExits.AddRange(newModuleExits.Where(e => e != exitToMatch));
}
pendingExits = newExits;
}
I've already tried several methods of detecting overlaps, including triggers and SweepTest, but none have worked. Essentially, I'm looking at a way to change the algorithm to do the following things in addition to what it already does:
Detect if the next gameobject to be spawned will overlap an already existing gameobject.
If so, then spawn a gameobject that won't overlap the already existing gameobject.
If you want to take a look at the section of code I posted above in context, the source code for the tutorial I am following can be found here.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity Colliders are Overlapping/Intersecting 2 Answers
Making a bubble level (not a game but work tool) 1 Answer
Generating terrain radially 1 Answer