I’m trying to get the horizontal FOV given the camera FOV and Camera Aspect ratio so I can place parts in every corner of the screen.
local camera = game.Workspace.CurrentCamera
local cameraCFrame = game.Workspace.CameraNode.CFrame
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
local cameraConnect = game:GetService("RunService").RenderStepped:Connect(function()
camera.CFrame = cameraCFrame
end)
local function getHorizontalFov(vFov)
local viewportSize = game.Workspace.CurrentCamera.ViewportSize
local aspectRatio = viewportSize.X/viewportSize.Y
local cameraHeightAt1 = math.tan(math.rad(vFov) * .5)
return math.deg(math.atan(cameraHeightAt1 * aspectRatio) * 2)
end
local function createViewModel()
local vFOV = camera.FieldOfView
local hFOV = camera.FieldOfView --getHorizontalFov(vFOV)
print(vFOV, hFOV)
local corners = {
topLeft = cameraCFrame * CFrame.Angles(math.rad(vFOV/2), math.rad(hFOV/2), 0) * CFrame.new(0,0,-15),
topRight = cameraCFrame * CFrame.Angles(math.rad(vFOV/2), -math.rad(hFOV/2), 0) * CFrame.new(0,0,-15),
bottomLeft = (cameraCFrame * CFrame.Angles(-math.rad(vFOV/2), math.rad(hFOV/2), 0)) * CFrame.new(0,0,-15),
bottomRight = (cameraCFrame * CFrame.Angles(-math.rad(vFOV/2), -math.rad(hFOV/2), 0)) * CFrame.new(0,0,-15)
}
for corner,coordinateframe in next, corners do
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1,1,1)
part.CFrame = CFrame.new(coordinateframe.Position)
part.Parent = game.Workspace
end
end
createViewModel()
Here is my result using my horizontal FOV calculation(Camera is set to the red node, didn’t show with camera on the node because you cant see any of the parts at all)
And here is the result using the default FOV (as in not calculating horizontal, default 70 for both. Would probably work for box monitors)
If you don’t know why these are placing directly on the corners, let me know, any help appreciated <3