Advertisement
Quoteory

Sphere

Aug 8th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.15 KB | None | 0 0
  1. -- Sphere
  2. -- Quoteory
  3. -- August 8, 2019
  4.  
  5. --[[
  6.    
  7.  
  8. --]]
  9.  
  10.  
  11.  
  12. local Sphere = {}
  13.  
  14. local spherePart = Instance.new("Part")
  15. spherePart.BrickColor = BrickColor.White()
  16. spherePart.Anchored = true
  17.  
  18. function inRadius(Mag, minRadius, maxRadius)
  19.     return Mag >= minRadius and Mag <= maxRadius
  20. end
  21.  
  22. function Sphere:Create(Radius, PartSize, Parts, Position)
  23.    
  24.     local Parts = Parts/3
  25.     local centerCFrame = CFrame.new(Position)
  26.     local SizeX = PartSize.X
  27.     local Width = SizeX * Parts
  28.  
  29.     for x = 1, Parts do
  30.         for y = 1, Parts do
  31.            
  32.             for z = 1, Parts do
  33.            
  34.             local Offset = CFrame.new(-(Width/2)-SizeX/2, -(Width/2)-SizeX/2, -(Width/2)-SizeX/2)
  35.             local CF = centerCFrame * CFrame.new(SizeX * x, SizeX*y, SizeX * z) * Offset
  36.            
  37.             local minRadius, maxRadius = Radius - SizeX, Radius + SizeX
  38.            
  39.             local isInRadius = inRadius(math.floor((centerCFrame.Position - CF.Position).magnitude), minRadius, maxRadius)
  40.            
  41.                 if isInRadius then
  42.            
  43.                 local newPart = spherePart:Clone()
  44.                 newPart.Size = PartSize
  45.                 newPart.CFrame = CF
  46.                 newPart.Parent = workspace
  47.                
  48.                 end
  49.                
  50.             end
  51.            
  52.         end
  53.     end
  54.    
  55. end
  56.  
  57. return Sphere
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement