How can I get these objects to stop spawning on the road?

I have a infinite road game with biomes:

I need help with getting the scenery to not spawn on the road.

I just choose a random x and z offset but keep the same y position.

Could you make a region or box covering the road, then check if the scenery is touching said region/box?

Make a raycast at the location you want to spawn the objects, check if the ray hits the road, if it does then don’t spawn the tree. You could also make it a bit more advanced, by taking the position you want the tree, and then make 4 rays, offset with X-amount of studs in each direction, if any of the rays hits the road, don’t spawn the tree, this does so the tree does not spawn right next to the road, but a minimum of X-amount of studs away from the road.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.