Sphere create

 avatar
MatsProg
lua
a year ago
1.8 kB
1
Indexable
Never
-- Define the size and position of the figure
local figureSize = Vector3.new(4, 4, 4)
local figurePosition = Vector3.new(0, 5, 0)

-- Define the parts that will make up the figure
local partTemplate = Instance.new("Part")
partTemplate.Anchored = true
partTemplate.CanCollide = false
partTemplate.Material = Enum.Material.Neon
partTemplate.Color = Color3.new(1, 1, 1)
partTemplate.Transparency = 0.5
partTemplate.Size = Vector3.new(1, 1, 1)

-- Define the function to create a sphere part
local function createSpherePart(position, radius)
    local part = partTemplate:Clone()
    part.Shape = Enum.PartType.Ball
    part.Size = Vector3.new(radius * 2, radius * 2, radius * 2)
    part.Position = position
    part.Parent = game.Workspace
    return part
end

-- Define the function to create a block part
local function createBlockPart(position, size)
    local part = partTemplate:Clone()
    part.Shape = Enum.PartType.Block
    part.Size = size
    part.Position = position
    part.Parent = game.Workspace
    return part
end

-- Build the sphere figure
local sphereRadius = figureSize.X / 2
for x = -sphereRadius, sphereRadius do
    for y = -sphereRadius, sphereRadius do
        for z = -sphereRadius, sphereRadius do
            local position = Vector3.new(x, y, z) + figurePosition
            local distanceFromCenter = (position - figurePosition).Magnitude
            if distanceFromCenter <= sphereRadius then
                createSpherePart(position, 0.5)
            end
        end
    end
end

-- Build the block figure
for x = -figureSize.X / 2, figureSize.X / 2 do
    for y = -figureSize.Y / 2, figureSize.Y / 2 do
        for z = -figureSize.Z / 2, figureSize.Z / 2 do
            local position = Vector3.new(x, y, z) + figurePosition
            createBlockPart(position, Vector3.new(0.8, 0.8, 0.8))
        end
    end
end