Hello, I’m currently having a problem where buildings are generating in weird places on a randomly generated planet.
I want the buildings to generate at the planets ground level.
Here’s the problem I’m currently getting.
I’m using DutchDeveloper’s Cube generation script to generate the buildings
function getRandomCFrame(object)
local X = object.Size.X/2
local Y = object.Size.Y/2
local Z = object.Size.Z/2
local RX = math.random(-X,X)
local RZ = math.random(-Z,Z)
local RY = math.random(-Y,Y)
return object.CFrame*CFrame.new(RX,RY,RZ)
end
function generateSimpleBuildings(planet)
local buildings = game.ReplicatedStorage.Civilizations.Simple:GetChildren()
-- Create a folder to store all the buildings
local buildingsFolder = Instance.new("Folder", planet)
buildingsFolder.Name = "Buildings"
for i = 20,0,-1 do
local randomBuilding = buildings[math.random(1,#buildings)]:Clone()
randomBuilding.Parent = buildingsFolder
local randomCF = getRandomCFrame(planet.Outer)
randomBuilding:SetPrimaryPartCFrame(randomCF
)
-- ROTATE BUILDINGS
randomBuilding:SetPrimaryPartCFrame(CFrame.new(randomBuilding.PrimaryPart.Position, -planet.Outer.Position))
wait(1)
end
end
How can I fix this?