Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Sphere
- -- Quoteory
- -- August 8, 2019
- --[[
- --]]
- local Sphere = {}
- local spherePart = Instance.new("Part")
- spherePart.Anchored = true
- spherePart.CastShadow = false
- function inRadius(Mag, minRadius, maxRadius) -- returns if a Part is between the min and max radius, or if it's less than the min radius (inner sphere)
- local targetRadius = (Mag >= minRadius and Mag <= maxRadius)
- local innerRadius = Mag < minRadius
- if targetRadius then
- return "targetRadius"
- elseif innerRadius then
- return true
- end
- end
- function newSpherePart(Size, CF, Trans, Color, Parent)
- local newPart = spherePart:Clone()
- newPart.Size = Size
- newPart.CFrame = CF
- newPart.Transparency = Trans
- newPart.BrickColor = Color
- newPart.Parent = Parent
- return newPart
- end
- function Sphere:Create(Radius, PartSize, Parts, Position)
- local Parts = Parts/3 -- amount of parts that shape will be
- local centerCFrame = CFrame.new(Position)
- local Size = Vector3.new(PartSize, PartSize, PartSize) -- the size of the sphere parts
- local Width = PartSize * Parts -- width of the presphere (like a cube)
- -- this generates parts in a cube and detects if they are within a certain radius and does stuff based on that
- for x = 1, Parts do
- for y = 1, Parts do
- for z = 1, Parts do
- local Offset = CFrame.new(-(Width/2)-PartSize/2, -(Width/2)-PartSize/2, -(Width/2)-PartSize/2)
- local CF = centerCFrame * CFrame.new(PartSize * x, PartSize*y, PartSize * z) * Offset
- local minRadius, maxRadius = Radius - PartSize, Radius + PartSize
- -- min and max radius, think of it like the spheres outer shell
- local isInRadius = inRadius((centerCFrame.Position - CF.Position).magnitude, minRadius, maxRadius)
- -- calls inRadius() and gets a return value
- if isInRadius then -- doesn't spawn a part if it's not within radius
- if isInRadius == "targetRadius" then
- newSpherePart(Size, CF, 0, BrickColor.Red(), workspace)
- else
- newSpherePart(Size, CF, 0, BrickColor.Gray(), workspace)
- end
- end
- end
- end
- end
- end
- return Sphere
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement