Skip to content

Instantly share code, notes, and snippets.

@badcc
Created June 2, 2017 18:13
Show Gist options
  • Save badcc/3c55742057ed2c62509b9c8705fbca7f to your computer and use it in GitHub Desktop.
Save badcc/3c55742057ed2c62509b9c8705fbca7f to your computer and use it in GitHub Desktop.
-- How many pixels (width) is 1 stud at depth d from camera
local function DepthToPixels(Depth)
local Camera = workspace.CurrentCamera
local Viewport = Camera.ViewportSize
local Ratio = Viewport.X/Viewport.Y
local h = math.tan(math.rad(Camera.FieldOfView)*0.5)
return Viewport.X/(2*Depth*h*Ratio)
end
print(DepthToPixels(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment