once the ray hits the wall, its direction, or maybe just the component of the ray that goes along the surface is kept. either solution will do, I think the latter makes more sense. In other words, I need to find the projection of the ray onto the wall
You can just cast raycast and if it hitted wall it will start new raycast in wall direction:
example:
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {workspace.cast}
local ray = workspace:Raycast(workspace.cast.Position,workspace.cast.CFrame.LookVector*100,params)
if ray then
if ray.Instance then
local params2 = RaycastParams.new()
params2.FilterType = Enum.RaycastFilterType.Exclude
local a = Instance.new('Part')
params2.FilterDescendantsInstances = {ray.Instance,a}
a.Position = ray.Instance.Position
a.Rotation = ray.Instance.Rotation
local ray2 = workspace:Raycast(ray.Position,a.CFrame.XVector*100,params2) -- you can change XVector(right) to -XVector(left)
if ray2 then
if ray2.Instance then
print(ray2.Instance.Name)
end
end
a:Destroy()
end
end