How to use rays for world generation?

I want to make an infinite world and I already have the terrain generation made. But one thing I want to do is make structures and mobs that spawn randomly around the player(with some distance of course).

So what I was thinking of doing since the world generation isn’t flat and predictable, I can use rays shot down from the sky and when they hit the terrain it will clone a structure from replicated storage and plop it down there.

I have no experience with raycasting very much, I have done it before to make a walking NPC but that is pretty much it. So if anyone is seeing this with more experience with raycasting than me, make sure to reply some thoughts or ideas on how to do this.

1 Like