I’m trying to make a visible ray, but the visible ray’s size keeps going far past the point where the ray hit something
Here’s my code:
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Blacklist
local origin = root.CFrame * Vector3.new(0, 0, -1)
local dir = mouse.Hit.lookVector.Unit * 200
local result = workspace:Raycast(origin, dir, params)
if result then
local between = (result.Position - origin)
local midpoint = origin + (between.Unit * between.Magnitude) / 2
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.BrickColor = BrickColor.Red()
part.Material = Enum.Material.Neon
part.Parent = workspace
part.CFrame = CFrame.new(midpoint, origin)
part.Size = Vector3.new(0.5, 0.5, dir.Magnitude)
end