Minecraft esc sphere generator

This script will generate a sphere like Minecraft. It will use a for loop to go through each point in 3D space and check if it is inside the sphere. If it is, then it will create a block at that position.

--[[

This script will generate a sphere like Minecraft:

--]]

local radius = 10 -- the radius of the sphere

local center = Vector3.new(0,0,0) -- the center of the sphere

local blocks = {} -- the table that will hold our blocks

-- create a for loop that goes from -radius to radius

for x = -radius, radius do

	for y = -radius, radius do

		for z = -radius, radius do

			-- calculate the distance from the center of the sphere

			local dist = (x*x + y*y + z*z)^0.5

			-- if the distance is less than or equal to the radius, then this point is inside the sphere

			if dist <= radius then

				-- calculate the position of the block
				
				local block = Instance.new("Part", workspace)
				block.Size = Vector3.new(4, 4, 4)
				local pos = Vector3.new(x * block.Size.x,y*block.Size.y,z*block.Size.z) + center
				block.Anchored = true
				block.Position = pos

				-- create the block and add it to the table
				
				table.insert(blocks, block)

			end

		end

	end

end
2 Likes

Minecraft is very full of spheres.

1 Like