Exclude region3 from another region3

Hello developers,
I am working on a few functions that should spawn some object (function parameter) at a random position within a Region3 or part.

Now the problem is that within that Region3 there can be other buildings, which I’d like to exclude from the region so the object won’t spawn there (so the random position will not be set within that building).

I’ve heard that WorldRoot:FindPartsInRegion3 can take up lots of resources.

I’ve looked on the DevForum for ways to make this, such as:

  1. non-square region
  2. “Region with a hole”
  3. how to exclude things from region3

(and of course, I included Roblox keywords)

But couldn’t find anything related.

Illustration of my problem:
image

Idea for an alternative

I’ve thought of checking whether the random position is in the part, and if it is, get another position.

But the problem is that to check if it is in the part I’ll have to use FindPartsInRegion3 for the part’s box right? And there are chances for it to spawn in the excluded area again, which will slowly eat up the memory and performance… :sweat:

Is it possible? Is there a way to achieve this or a better alternative?

You could use FindPartsInRegion3WithIgnoreList so that when you run FindPartsInRegion3 it will ignore the instances(buildings) you put in that list.

The thing is that I want to find a random position, not a part within that region, but the problem is that this random position could be inside of a building (region I want to exclude).

Is there a way to do that? Or an alternative?

Here’s another drawing to explain the issue:
image
You can see the purple dot is a random position inside the region I want to exclude.

I can think of two possible ways:

  1. You could make multiple regions3 areas around the excluded areas, select a region at random and then find a random position within that region to spawn the object.

  2. You could place a single parts all over the map making sure they are not to close each other and to the excluded areas and then select a part at random and spawn the object in a random position within a certain radius of the selected part.

Both seem like a massive work around but it’s all I could come up with.

Edit:
Just thought of a third possible way:

Make region3 areas within the excluded areas, and if the random position you selected is within that region3, try find another random position.

2 Likes

I’ve thought of that, but within large maps, it is very hard to do.

Thought of this too, the problem is that the massive use of FindPartsInRegion will create lag and performance issues.

Although lots of work, that actually seems pretty reasonable.
I think I’ll find the excluded objects, and create regions around them.

Thanks for the help :slightly_smiling_face:!