I’ve been creating a survival game, and I need to be able to spawn lots of things over the very large map that I made (around 4k by 4k studs including ocean). I would do the easy way by placing object spawn locations but this would require me to create many many parts which would take a lot of time and reduce preformance.
One of the main things I need to spawn are animals, my idea was to get a random location within a radius around a player, check if it’s over land then spawn the animal on the ground level (which I would also need to figure out how to get)
(blue being the radius)
but I dont know how I would script this.
for trees or rocks, I would need to probably just pick a random location, get the ground level and biome then spawn in the correct object for that biome (I’ll worry about this another time)
If anybody has any ideas, or knows how I can get a random location from a radius of the player please let me know
This is over simplified and you can refine the rules for selection, but I would use the idea from your image and spawn within a radius of the player in 2D. I would select a random position that isn’t too close to the player and to get the height I would raycast from just over the highest point of the map and get the RaycastResult.Position.Y and combine it with the randomized position in 2D you used for the raycast origin. If you wanted to make sure it doesn’t spawn over the edge of the map, you can clamp the position and if you wanted to blacklist regions you maybe could make it recursive. Because it is random, it might not be a good idea to use recursion but you would have to test that.
I do really like this idea, I dont think I have to worry about anything spawning over the edge of the map though as I can detect whether the raycast hits the ground or if it hits something else. I will try this after I research more about roblox raycasting. Thanks for the help!