hello, is there a way to see what's happening behind the editor ?

if i use keep width i can get the camera horizontal limit by dividing the size by 2 translation.x = clamp(translation.x , limit_Left + size/2, limit_Right - size/2 );

but i will loose the upper and bottom border, the only way to make the limit work vertical is by selecting keep height in the editor Ive tried using translation.z = clamp(translation.z , limit_Up + (size / OS.window_size.aspect()) , limit_Down - (size / OS.window_size.aspect()) ); but it doesnt work the value is never precise

Is there a way to calculate the aspect ration / Keep Height in code ?

Is there a way to calculate the aspect ration / Keep Height in code ?

Yes, use the Vert- (Keep Width) to Hor+ (Keep Height) FOV conversion formula:

# This assumes an horizontal FOV of 90 degrees. Change if needed.
var horizontal_fov = 90

# Use floating-point divison, not integer division.
var aspect_ratio = 4.0/3.0
var new_aspect_ratio = 16.0/9.0

var vertical_fov = atan(tan(horizontal_fov * PI / 360) * 1 / aspect_ratio) * 360 / PI
var new_horizontal_fov = atan(tan(horizontal_fov * PI / 360) * new_aspect_ratio / aspect_ratio) * 360 / PI

Or, if you need to know the vertical FOV for another aspect ratio when using the Keep Width aspect mode:

var horizontal_fov = atan(tan(vertical_fov * PI / 360) * aspect_ratio) * 360 / PI

var new_horizontal_fov = atan(tan(horizontal_fov * PI / 360) * new_aspect_ratio / aspect_ratio) * 360 / PI

Note that the above code is untested (I translated it from a Go project of mine).

In general, you should use keep height. At least on desktop, there is more variation with the monitor width than with the height (for example, ultrawide monitors). So if you use keep width, it will look incorrect and cropped on many people's screens. This is different if you are on mobile, for example with a portrait aspect ratio.

But what is it you are trying to do exactly? Though @Calinou 's formula is correct, there should not ever be a need to know the exact dimensions or aspect ratio if you make everything responsive and dynamic.

@Calinou said:

Yes, use the Vert- (Keep Width) to Hor+ (Keep Height) FOV conversion formula:

Or, if you need to know the vertical FOV for another aspect ratio when using the Keep Width aspect mode:

I think i doesnt work in case... iam trying to figure the distance, of the level upper and bottom corners, based on the camera position and the camera size... ( maybe the func distance_to will work )

@cybereality said: In general, you should use keep height. At least on desktop, there is more variation with the monitor width than with the height (for example, ultrawide monitors). So if you use keep width, it will look incorrect and cropped on many people's screens. This is different if you are on mobile, for example with a portrait aspect ratio.

But what is it you are trying to do exactly? Though @Calinou 's formula is correct, there should not ever be a need to know the exact dimensions or aspect ratio if you make everything responsive and dynamic.

Iam trying to clamp the camera position once it reaches the end corner's of the level, also based on the camera size... I can make it work using keep width, but the keep height there's no way to get an exact value, maybe its the camera angle ( -45 ) the value keeps altering based on the camera position in the var vertical_fov = atan(tan(horizontal_fov * PI / 360) * 1 / aspect_ratio) * 360 / PI for example the values are too high ( -34.515877 ) the correct number for the camera.z clamp is translation.z = clamp(translation.z , 3.2 , 10.8 ); but this value changes once the camera zoom is changed, also i dont think it corresponds to the level distance in coordinates

9 months later