What? Read this:
29+1 chrs
What? Read this:
29+1 chrs
So, you haven’t used the “F” key. That’s fine. You want to force focus on the object while auto setting the distance such that the full object (2 corners) is always visible and maximized on screen.
Why 2 parts? Simplify your problem. Make a cube where those 2 parts are opposite corners.
I was actually working on something like this not too long ago for viewports:
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local model = nil -- insert a model here
camera.FieldOfViewMode = Enum.FieldOfViewMode.Diagonal
camera.FieldOfView = 70 -- adjust the field of view as wanted
local fov = math.rad(camera.FieldOfView)
local bounding = model:GetExtentsSize()
local boundingY = bounding.Y
local boundingX = bounding.X
local boundingZ = bounding.Z
local biggest = math.max(boundingY,boundingX, boundingZ)
local offsetX
local vpSize = camera.ViewportSize
local fovx = 2 * math.atan( math.tan(fov * 0.5) * (vpSize.X / vpSize.Y))
offsetX = (biggest * 0.5 )*(1/math.tan(fovx * 0.5))
It’s up to you to apply this to the camera, but this should work as it has for me.
The only downside is that both parts have to be in a model so that you can get the extents size.
offsetX is how far away the camera should be from the center of the “model” in the x-axis.