Determine Abstract Bounds

I’m looking for an optimal way to determine if a point is in a region with an abstract shape. I have a snowy biome (see below), and I want to determine whether or not a Vector3 point falls within its bounds. The easiest solution would be to raycast and check raycastResult.Material, but that would prevent me from using the material anywhere else and is not an option. What is an optimal way to determine when a point falls within a biome?

1 Like

Define a point that we will call “x”, it is outside of the biome. It can be literally anywhere, as long as it’s outside of the biome. Do a series of small raycasts going towards the point you are checking. If there is an odd number of intersections with the edges of the shape, then the point is inside, otherwise it’s outside.
Right now, it doesn’t quite work. This is because raycasts only detect entering a part, not leaving it. To detect leaving it, simply make another raycasts going in the exact opposite direction.

Also, what are more specifics on the biome. If there is another biome in the middle, then would a point in the center biome be considered as being in the outside biome? This could drastically simplify the approach.

In the following image, the sand would be one biome, and the snow would be another biome. The sand biome would not exist over the snow.

Additionally, there may be instances like this where two biomes largely overlap. Again, the sand would be one biome and the snow would be another. The snowy biome would not exist over the sand.

Ok then the approach I described should work. Maybe when I get on my PC tomorrow I’ll write some code for you, I will probably forget for a month though.

1 Like