How to calculate maximum and minimum Y value from object of player camera

  1. What do you want to achieve?

Given a part, I want to find the maximum and minimum Y values ​​at which the camera does not go out of the part.

  1. What is the issue?

It works perfectly with other cameras, but not with workspace.currentcamera. It seems to be because the viewportsize is different.

camZoom indicates how far the camera is from the part.

local h = math.tan(math.rad(cam.FieldOfView / 2)) * camZoom

local top, bottom = part.Size.Y / 2, - part.Size.Y / 2
		
return top - h, bottom + h

What does the top and bottom refer to?