This might sound kind of confusing but I want to make it so the green lines between the green dot and the start position are collideable and make it so the ray gets cut at the hit position.
To do this I want to have it so the “TemplateDot” CFrame and Size is the same as the CFrame of the projected ray. Any help is appreciated.
Here’s an image of what the ray looks like as of right now for context:
--<< NotFrindow >>--
local projector = script.Parent
--<< Raycast Params >>--
local ignoreList = {}
for _ , v in ipairs(workspace:GetDescendants()) do
if v:IsA('BasePart') and v.Transparency == 1 then
table.insert(ignoreList, v)
end
end
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = ignoreList
print("D.O.T.S Projector Ignore List:")
print(ignoreList)
--<< Functions >>--
function castDot(direction)
local raycastResult = workspace:Raycast(projector.Position, direction, params)
RaycastParams.new()
local newDot = projector.TemplateDot:Clone()
newDot.Parent = projector.Dots
newDot.StartPoint.WorldPosition = projector.Position
newDot.EndPoint.WorldPosition = raycastResult.Position
end
for i = 1, 200 do
wait(0.05)
castDot(Vector3.new(math.random(-180, 180), math.random(0, 180), math.random(-180, 180)))
end
You can do CFrame.lookAt from the start to the end of the ray. Then you need to change the Position of that cframe to be the middle of the ray. This is the CFrame your part should have.
--<< NotFrindow >>--
local projector = script.Parent
--<< Raycast Params >>--
local ignoreList = {}
for _ , v in ipairs(workspace:GetDescendants()) do
if v:IsA('BasePart') and v.Transparency == 1 then
table.insert(ignoreList, v)
end
end
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = ignoreList
print("D.O.T.S Projector Ignore List:")
print(ignoreList)
--<< Functions >>--
function castDot(direction)
local raycastResult = workspace:Raycast(projector.Position, direction, params)
RaycastParams.new()
local newDot = projector.TemplateDot:Clone()
newDot.Parent = projector.Dots
newDot.StartPoint.WorldPosition = projector.Position
newDot.EndPoint.WorldPosition = raycastResult.Position
newDot.CFrame = CFrame.lookAt(newDot.StartPoint.WorldPosition, newDot.EndPoint.WorldPosition)
newDot.Size = Vector3.new(raycastResult.Distance, 0.001, 0.001)
end
for i = 1, 200 do
wait(0.05)
castDot(Vector3.new(math.random(-180, 180), math.random(0, 180), math.random(-180, 180)))
end
Using the new code I wrote above, it came out like this:
CFrame.lookAt creates a CFrame whose position is the first position given. You need to change the position to be the center of the ray: newDot.CFrame = newDot.CFrame - newDot.CFrame.Position + (StartPoint + EndPoint) * 0.5