Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My sphere generator makes cylinders instead? Help?

So I know something is wrong with the math for the x and z parts of the CFrame, but I can't seem to figure out what the problem is. Its making what is supposed to be a sphere into a cylinder instead because the rings at the top aren't getting closer to each other. Currently its making the "sphere" look like this

Here is the code:

rings = 12
segs = 16
r = 20 -- radius

center = workspace.Core.PrimaryPart.Position 
-- The center of the sphere, which can be any vector3 value

for i = -90,90,180/rings do
	for j = 0,360 - (360/segs),360/segs do
		part = Instance.new("Part")
		part.Name = "SphereWall"
		part.CanCollide = true
		part.Anchored = true
		
		part.Size = Vector3.new(4,4,1)

		part.CFrame = CFrame.new(Vector3.new(
			center.X + (math.cos(math.rad(j)) * r),
			center.Y + (math.sin(math.rad(i)) * r),
			center.Z + (math.sin(math.rad(j)) * r)), 
			center)
		

		part.Parent = script.Parent
	end
end

4 comments

0

you prob need to change the variables.... the value of the variables

0

Really? Theres a shape named Ball...................................... wonder what that shape looks like...............

0

@hiiimgoodpack oh gee... maybe i want to have a hollow sphere made out of as little parts as i want... so i can put stuff in them... while maintaining a blocky feeling in the sphere... the nerve of some people, smh    EDIT: In the picture... in the middle of the "sphere"... i think those are cylinders too... you think?

0

then use solid modeling @Zukaazora

1 answer

Well after enough searching around, i found a solution (The link is to stackoverflow.com) and applied it in this code if anyone wants to use it, since there aren't any hollow sphere generators I could find on the web:

ri = 12
se = 16
r = 40

center = workspace.Core.PrimaryPart.Position

for i = 0,ri do
	for j = 0,se - 1 do
		local part = Instance.new("Part")
		part.Name = "SphereWall"
		part.CanCollide = true
		part.Anchored = true
		
		local s = Enum.SurfaceType.SmoothNoOutlines
		part.TopSurface = s
		part.BottomSurface = s
		part.RightSurface = s
		part.LeftSurface = s
		part.FrontSurface = s
		part.BackSurface = s
		
		local c = 10 --(2*math.pi*r)/(360/r)
		part.Size = Vector3.new(c,c,1)
		
		part.CFrame = CFrame.new(Vector3.new(
			center.X + math.sin(math.pi * (i/ri)) * math.cos(math.pi*2 * (j/se)) * r,
			center.Y + math.cos(math.pi * (i/ri)) * r,
			center.Z + math.sin(math.pi * (i/ri)) * math.sin(math.pi*2 * (j/se)) * r), 
			center)
		part.Parent = script.Parent
	end
end

Also, the result of the script looks like this

This discussion is preserved as it was. New answers, comments, and votes are closed.