So I made a custom raycast function that hits parts multiple times (instead of only once like normal raycasts do) but I found out that, if the starting position is inside a part, then it won’t hit the part.
So how can I make it actually hit the part it’s inside of?
The parts I’m using for testing:
Here’s the code for the function, in case it reveals I messed up on something:
function HitboxService.raycastMultiple(start, direction, raycastParams:RaycastParams?):{BasePart}
local raycastParams = raycastParams or RaycastParams.new()
local isWhitelist = raycastParams.FilterType == Enum.RaycastFilterType.Whitelist
local partsRaycast = {}
while true do
local hit = workspace:Raycast(start, direction, raycastParams)
if hit then
local hitPart = hit.Instance
table.insert(partsRaycast, hitPart)
local filterDescendantsInstances = raycastParams.FilterDescendantsInstances
if isWhitelist == true then
table.remove(filterDescendantsInstances, hitPart)
else
table.insert(filterDescendantsInstances, hitPart)
end
raycastParams.FilterDescendantsInstances = filterDescendantsInstances
else
return partsRaycast
end
end
return partsRaycast
end
and here I use the module:
local rayStartPosition:Vector3 = workspace.raycastStartPoint.Position
local rayEndPosition:Vector3 = workspace.raycastEndPoint.Position
for i, v in ipairs(HitboxService.raycastMultiple(rayStartPosition, rayEndPosition - rayStartPosition)) do
print(v.Name)
end