Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Camera FOV doesn't work how i expect it to?

Asked by
lokkut 20
5 years ago
local x = workspace.CurrentCamera

local n = Instance.new("Part")
n.Parent = workspace 
n.Anchored = true;
n.Transparency = 0.5;
n.CanCollide = false;
local d = 6; -- dsitance from camera
local w = Instance.new("BlockMesh")
w.Scale = Vector3.new(1,1,0)
w.Parent = n;

function gn(v2)
    local m = x.CFrame + (x.CFrame.LookVector * d) -- midpoint
    local mx,my = x.ViewportSize.X/2,x.ViewportSize.Y/2; -- midpoint px
    m = m * CFrame.new( d*(v2.X-mx)/x.ViewportSize.Y, d*(my-v2.Y)/x.ViewportSize.Y, 0 ); -- offset block
    return m
end

game["Run Service"].RenderStepped:connect(function()
    --x.FieldOfView = (x.FieldOfView+0.25)%80 -- use this to make it obvious whats wrong
    local a = (math.pi*x.FieldOfView/360)
    local w2 = math.sin(a) * (d);
    n.Size = Vector3.new( w2, w2, 0.2 ); -- set size based on FOV
    n.CFrame = gn(x.ViewportSize/2) -- just take the middle
end)

i was expecting this to create a block, put it in front of the camera, and have it be directly in the center and half the height. however it just doesn't work and it somehow depends on what the FOV is. the horizontal dimension is completely wrong so i'm not even going to pretend i know about that one

any ideas why?

Answer this question