I wanna make algorithm of raycasting that works like:
We got origin from, like o(0, 0, 0) to d(1000, 0, 0).
And in roblox we can’t make that big raycast, because of lag.
So, i wanna make many raycasts, like 4, each to 250 studs
And i wanna make something like that:
We go full 250 studs first. then again.
If we hit nothing, we go on half back, 250/2 = 125 studs back
And make ray on 125 studs again.
Until ray will very very small.
This isn’t very practical in roblox because we don’t get low level access to say the individual polygons or anything like that. There isn’t really any fast option in roblox that would ever perform any better than the built in ray-casting system.
You can probably begin by segmenting the direction in however many pieces you want and then raycasting from a new origin corresponding to how many iterations you’ve done:
local function RayCastInSegments(Origin, Direction, RaycastParams, Segments)
local Piece = Direction/Segments --If the Segments variable is 4, this will be 1/4 of the direction
for i = 1, Segments do
local result = workspace:Raycast(Origin, Piece, RaycastParams)
if result ~= nil then -- If something was found on the raycast then return it
--Nothing was found and we need to continue going further
Origin += Piece --Increment origin to the next raycast