Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function RecurseRaycast(qRay, IgnoreList) -- IgnoreList is a table of objects to ignore.
- local Returns = {};
- local OriginalLength = qRay.Direction.magnitude;
- local Raycast;
- function Raycast(qRay, IgnoreList)
- local Hit, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(qRay, IgnoreList);
- if (Hit) then
- table.insert(Returns, {Hit,Pos,Normal});
- table.insert(IgnoreList, Hit);
- local NewRay = Ray.new(qRay.Origin, qRay.Direction.unit * (OriginalLength - (qRay.Origin - Pos).magnitude ))
- return Raycast(NewRay, IgnoreList)
- end
- end
- Raycast(qRay, IgnoreList);
- return Returns;
- end
- -- Example of usage
- local Returns = RecurseRaycast(
- Ray.new(workspace.RayTester.Position, workspace.RayTester.CFrame.lookVector * 500),
- {workspace.RayTester}
- )
- if (#Returns == 0) then
- print("Ray hit nothing.");
- else
- for i,v in ipairs(Returns) do
- print(unpack(v))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement