Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My sphere generator makes cylinders instead? Help?

Asked by 7 years ago
Edited 7 years ago

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
0
you prob need to change the variables.... the value of the variables greatneil80 2647 — 7y
0
Really? Theres a shape named Ball...................................... wonder what that shape looks like............... hiimgoodpack 2009 — 7y
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? Zukaazora 30 — 7y
0
then use solid modeling @Zukaazora hiimgoodpack 2009 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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

Ad

Answer this question