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:
non-square region
“Region with a hole”
how to exclude things from region3
(and of course, I included Roblox keywords)
But couldn’t find anything related.
Illustration of my problem:
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…
Is it possible? Is there a way to achieve this or a better alternative?
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:
You can see the purple dot is a random position inside the region I want to exclude.
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.
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.