Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Placing items in random places keeping elevations in mind?

Asked by
Newrown 307 Moderation Voter
4 years ago

I wanted to spawn items at random places around a map, however this map can have different elevations. I do not want to place blocks and spawn them in a part's place, I was wondering if there is a method I could look into that would help me achieve that?

So basically spawning something at random locations around the map, however make sure that it is directly on top of the surface of the ground.

I am not asking for code, I'm just asking for methods (with a brief explanation) to look into, and I will do my research.

Help is much appreciated.

0
You could use Ray.new to cast a ray from a height at the position you choose directly downwards to find the position it hits. The Y position would be the height of the terrain. darkelementallord 686 — 4y
0
Yeah I thought of that, however lets say there are buildings so if I want it to spawn inside a building then the ray would hit the ceiling, I could use IgnoreList however that means I have to put the ceiling of every single building into the ignore list, and what if it's more than one floor (the building) there has to be a more efficient way Newrown 307 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

If you're using Terrain and simply want to ignore all models (trees, buildings, etc), simply use https://developer.roblox.com/en-us/api-reference/function/Workspace/FindPartOnRayWithWhitelist and give it a whitelist of just {workspace.Terrain}

If you aren't using Terrain but just a bunch of parts, if you have all your parts in a single folder, you can pass that folder into the function instead and that will work too.

There is also an ignore list: https://developer.roblox.com/en-us/api-reference/function/Workspace/FindPartOnRayWithIgnoreList

0
That was the idea on my mind thanks for reaffirming it Newrown 307 — 4y
Ad

Answer this question