Need help with normalizing a cube (turning a cube into a sphere)

I am trying to turn a cube into a circle by normalizing the cube using the method in this topic by PapaBreadd in post 4, but I’m having the same problem as the original poster, being that it makes the cube look like this.

The solution didn’t help me at all. Although, it did say something about “Setting the points around the origin” (which in the original poster’s case was 0, 0, 0).

This is my code:

local runService = game:GetService("RunService")

function generateSphere(center, size)
	
	local verticesOnCube = {}
	local verticesOnSphere = {}
	
	local i = 0
	for x = 0, size do 
		for y = 0, size do
			for z = 0, size do
				i = i + 1

				verticesOnCube[i] = Vector3.new(x, y, z)
			end
		end
	end
	
	for i, o in ipairs(verticesOnCube) do
		local xyz = Vector3.new(o.X, o.Y, o.Z)
		verticesOnSphere[i] = (xyz - center).Unit + center
		
		local sphereVertex = verticesOnSphere[i]
		local part =  Instance.new("Part")
		part.Position = sphereVertex * 10
		part.Anchored =  true
		part.Size = Vector3.new(1, 1, 1)
		part.Parent = workspace
		runService.Heartbeat:Wait(5)
	end
end

--////////////////////

local center = Vector3.new(0, 0, 0)
local size = 10

generateSphere(center, size)

Any help would be appreciated. Thank you!

You’re putting the center in the corner of the cube, instead of the actual center of it.

The points are extending on each axis in one direction from the center, rather than being on either side of the center.

Try this:

	local i = 0
	for x = -size/2, size/2 do 
		for y = -size/2, size/2 size do
			for z = -size/2, size/2 size do
				i = i + 1

				verticesOnCube[i] = Vector3.new(x, y, z)
			end
		end
	end
1 Like

Yup, that worked perfectly. thank you for helping me!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.