How would you get exact offset for the sides of a any arbitrary Camera. I know you can the location of a Camera using Camera.CFrame
however I need a way to get the Top, Bottom, Left, and Right points of the Camera’s Veiwport.
The reason why I need this is right now I have a function that gets every part in a camera’s bounding box. However, the function dose not get every part within the Camera’s Veiw, so I want to improve it by casting multiple rays on the edges to get more parts returned from the function.
-- SOURCE: https://devforum.roblox.com/t/1728815/6
function GetPartsInView(Camera: Camera): {BasePart}
local parts = {}
for i, obj: BasePart in pairs(workspace:GetDescendants()) do
if (not obj:IsA("BasePart")) or obj:IsA("Terrain") then continue end
-- TODO: Add extra check that also detects parts that are just barily outside of veiw (Raycast sides)
-- Only add parts that are actually in the cameras veiw
local _, onScreen: boolean = Camera:WorldToScreenPoint(obj.Position)
if not onScreen then continue end
table.insert(parts, obj)
end
return parts
end
EDIT: All I know is that we would probably need to get the FOV of the Camera included in the calculation but I don’t know where to go from there.