- What do you want to achieve? Keep it simple and clear!
I want models I spawn in a script (using raycast) to spawn leveled with the ground, but it hasn’t been working so far.
- What is the issue? Include screenshots / videos if possible!
The models spawn like above or below the ground, and only a few models have actually worked.
- What solutions have you tried so far? Did you look for solutions on the Creator Hub?
Using the same script, here are results I have gotten:
the one above is one that worked, and the one below is one that didn’t work (these both use the same logic and script)
SOME solutions i have tried:
adding height / 2
using pivot to and bounding box / get extents to get the Y
more solutions that i dont feel like writing
Here is a snippet of my code:
local function getTrueBottom(model)
local minY = math.huge
for i, v in pairs(model:GetDescendants()) do
if v:IsA("BasePart") then
local bottom = v.Position.Y - (v.Size.Y / 2)
if bottom < minY then
minY = bottom
end
end
end
return minY
end
-- this part below is part of a bigger function but i just cut it out and only left the necessary parts for this problem
-- also the get true bottom function is not mine, but i decided to use it after many failed attempts of looking for solutions
local origin = Vector3.new(math.random(-475, 475), 100, math.random(-475, 475))
local direction = Vector3.new(0, -500, 0)
local rc = workspace:Raycast(origin, direction)
if rc and rc.Instance.Name == "Baseplate" then
pos = rc.Position
local structure = game.ServerStorage.structures[map]:FindFirstChild(strucName):Clone()
structure.Parent = workspace
if structure:IsA("Model") then
local trueBottom = getTrueBottom(structure)
local offset = pos.Y - trueBottom
structure:MoveTo(pos + Vector3.new(0, offset, 0))
else
-- ignore this ill do it later if its not a model
end
end

