How can I make a system where it makes a bunch of rectangles within a circle and when there’s a block within that circles any of those rectangles that are in the way will stop right when it collides with the ray?
Video example shown from another user who accomplished this:
The white part is an example of
the part it should detect and the blue is all the rectangles forming a circle
Can anybody tell me how I can make this?
Heres the code I that has come closest for now
local observerPart = workspace.Dot
local ignoredObjects = {workspace.Viewport}
local range = 10
local raysAmount = 360
local increasement = 10
local usedParams = RaycastParams.new()
usedParams.FilterType = Enum.RaycastFilterType.Blacklist
usedParams.FilterDescendantsInstances = ignoredObjects
local pi = math.pi
local function doRaycast(degree) -- Checks if a block is within its range
-- :: Calculate direction based on angle
local degreeToRadian = (degree / raysAmount) * pi * 2
local direction = Vector3.new(math.sin(degreeToRadian), 0, math.cos(degreeToRadian)) * range
-- :: Return raycast results
return workspace:Raycast(observerPart.Position, direction, usedParams)
end
local function instanceFound(degree, result) -- Changes block to be it's size determined by where the ray got hit
local origin, direction = observerPart.Position, result.Instance.Position + CFrame.new(Vector3.new(result.Instance.Position.X, observerPart.Position.Y, result.Instance.Position.Z),observerPart.Position)
local object = workspace.Viewport:FindFirstChild("HitBox"..degree)
if object then
object.CFrame = CFrame.new((origin + direction)/2, origin)
object.Size = Vector3.new(0.0875 * range, 1, (origin - direction).Magnitude)
else
object = game.ServerStorage.Dot:Clone()
object.Parent = workspace.Viewport; object.Name = "HitBox"..degree; object.Anchored = true
degree = math.rad(degree)
object.CFrame = CFrame.new((origin + direction)/2, origin)
object.Size = Vector3.new(0.0875 * range, 1, (origin - direction).Magnitude)
object.Color = Color3.fromRGB(57, 245, 255)
end
end
local function fill(degree) -- Fills up any clear spot
local origin, direction = observerPart.Position, Vector3.new(observerPart.Position.X + range * math.cos(degree), observerPart.Position.Y, observerPart.Position.Z + range * math.sin(degree))
local object = workspace.Viewport:FindFirstChild("HitBox"..degree)
if object then
object.CFrame = CFrame.new((origin + direction)/2, origin)
object.Size = Vector3.new(0.1 * range, 1, (origin - direction).Magnitude)
else
object = game.ServerStorage.Dot:Clone()
object.Parent = workspace.Viewport; object.Name = "HitBox"..degree; object.Anchored = true
degree = math.rad(degree)
object.CFrame = CFrame.new((origin + direction)/2, origin)
object.Size = Vector3.new(0.0875 * range, 1, (origin - direction).Magnitude)
object.Color = Color3.fromRGB(57, 245, 255)
end
end
while task.wait() do
for degree = 1, raysAmount, increasement do
local result = doRaycast(degree)
if result and result.Instance.Name ~= "HitBox" then
instanceFound(degree, result)
else
fill(degree)
end
end
end
Basically, it already fills up normally just with fewer parts so it’s not laggy.
Once it detects a part within its radius it changes but this one changes different boxes which aren’t even close to the block.