As you can see by the image below, there is a great distortion in my raytracing gui from using angled raycasts. The effect is mostly noticeable on the edges on less round objects.
I’ve tried using many math equations and formulas to counter this effect, but every time i fix the fisheye distortion, i get a new distortion on the sides of the field of view which gets worse for higher FOV.
I’ve seen many raytracing problems that avoid this issue by using the camera instance and it’s neat viewport functions for raycasting, but I cant seem to get the functions to work correctly for my code.
x = x + Resolution/2
y = y + Resolution/2
local Origin = CamPart.Position
local RayAngleY = math.rad(y / Resolution) * FieldOfView
local RayAngleX = math.rad(x / Resolution) * FieldOfView
local Direction = (CamPart.CFrame * CFrame.Angles(RayAngleY, RayAngleX, 0)).LookVector * RenderDistance
-- Cast ray
local Raycast = workspace:Raycast(Origin, Direction, Params)