Hey guys!
I’m currently working on binary space partionioning. It works so far. Now I need to add a random offset to make the resulting grid more procedural looking. I’ve been trying a few different approaches, but non of them seem to work. I am using bounds for that.
Here’s the method that splits the bounds:
private Tuple<Bounds, Bounds> SplitOne(Bounds bounds, GlobalConfig.SplitType splitType)
{
Bounds boundsOne, boundsTwo;
float rnd;
do
{
rnd = UnityEngine.Random.Range(-GlobalConfig.RandomSizeOffset, GlobalConfig.RandomSizeOffset);
} while (rnd == 0);
if (splitType == GlobalConfig.SplitType.Vertical)
{
boundsOne = new(
new Vector3(bounds.center.x - bounds.size.x / 4f, bounds.center.y, bounds.center.z),
new Vector3(bounds.size.x / 2f, bounds.size.y, bounds.size.z));
boundsTwo = new(
new Vector3(bounds.center.x + bounds.size.x / 4f, bounds.center.y, bounds.center.z),
new Vector3(bounds.size.x / 2f, bounds.size.y, bounds.size.z));
boundsOne.max = new(boundsOne.max.x + rnd, boundsOne.max.y, boundsOne.max.z);
boundsTwo.min = new(boundsTwo.min.x - rnd, boundsTwo.min.y, boundsTwo.min.z);
}
else
{
boundsOne = new(
new Vector3(bounds.center.x, bounds.center.y, bounds.center.z - bounds.size.z / 4f),
new Vector3(bounds.size.x, bounds.size.y, bounds.size.z / 2f));
boundsTwo = new(
new Vector3(bounds.center.x, bounds.center.y, bounds.center.z + bounds.size.z / 4f),
new Vector3(bounds.size.x, bounds.size.y, bounds.size.z / 2f));
boundsOne.min = new(boundsOne.min.x, boundsOne.min.y, boundsOne.min.z - rnd);
boundsTwo.max = new(boundsTwo.max.x, boundsTwo.max.y, boundsTwo.max.z - rnd);
}
return new(boundsOne, boundsTwo);
}
And here is the result:
As you can see, they are offset, but not connected and overlap each other.
This is what it looks like if I remove the random offset:
Do you guys have an idea how I can use the random offset without them overlapping? Like so:
Image source: How to Use BSP Trees to Generate Game Maps
Any help would be appreciated!