ok so this is the function where i calculate the size and position of the part
function getDimentions(cam)
local corners = {}
-- the 4 corners of the viewport
for x = 0, cam.ViewportSize.X , cam.ViewportSize.X do
for y = 0, cam.ViewportSize.Y , cam.ViewportSize.Y do
local ray = cam:ViewportPointToRay(x, y, 0)
local newPosition = ray.Origin + ray.Direction * RAY_DISTANCE
table.insert(corners, newPosition)
end
end
local center = (corners[2] + corners[3]) / 2
local size_x = (corners[1] - corners[2]).Magnitude
local size_y = (center - cam.CFrame.Position).Magnitude
local size_z = size_x
local coneCFrame = cam.CFrame * CFrame.new(0, 0, -size_y/2) * CFrame.Angles(math.rad(90), 0, 0)
local coneSize = Vector3.new(size_x, size_y, size_z)
return coneCFrame, coneSize
end
this is how i use it
local cFrame, size = getDimentions(photoCamera)
local viewCone = viewConeTemplate:Clone()
viewCone.CFrame = cFrame
viewCone.Size = size
and this is the part used
Union.rbxm (4.4 KB)
This function adjusts the vertical FOV to match a new viewport height while keeping the same perspective. Since FOV scales on the Y axis, resizing affects only the Y axis. For the X axis, aspect ratio handles scaling automatically, so FOV remains unaffected horizontally.
local function calculateFOV(originalFov, currentViewportSize, desiredViewportSize)
local rad = 2 * math.atan(math.tan(math.rad(originalFov) / 2) * (desiredViewportSize / currentViewportSize))
return math.deg(rad)
end
In my game, the viewport’s Y-axis size is halved, so you use calculateFOV(70, 1080, 1080/2)
to get the adjusted FOV. which returns 38.59
which is exactly what we need