How would I detect if screen/window is square?

Im basically making a Plague Inc. game, Making the World map an UI wasnt a good idea so I just put some huge parts with decals on it, with a camerapart above.

Recently I have been making this zoom in mechanic. It is doing well for now but I’ve noticed that the map cuts off from sides when the screen/window is square. My Idea is to move the camerapart higher above if the screen/window is square, but im not sure how to do it

local normalcamattachcframe = CFrame.new(-3.08400011, 83, 151.5, -1, 0, 0, 0, 0, 1, 0, 1, -0)
local squarescreencamattachcframe = CFrame.new(-3.08400011, 103, 151.5, -1, 0, 0, 0, 0, 1, 0, 1, 0)

if workspace.Camera.ViewportSize.X <= 850 and workspace.Camera.ViewportSize.Y <= 850 then
	TweenService:Create(workspace.CamAttach, TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = squarescreencamattachcframe}):Play()
else
	TweenService:Create(workspace.CamAttach, TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = normalcamattachcframe}):Play()
end
-- I used tweens instead of directly setting the cframe because I was planning on tweening it when the window size changes, a cool smooth transition

this method wasnt a good idea since there are devices with low resolutions such as iphone 4, 5, etc.
I appreciate any feedback and will definitely give credits if I get this working

It’s not letting me view the images/videos, but to detect if it’s a square you can calculate the aspect ratio and use a threshold. The closer the aspect ratio is to 1, the more square it is

local Camera = workspace.CurrentCamera
local aspectRatio = Camera.ViewportSize.X/Camera.ViewportSize.Y
-- When the aspect ratio is 1, it is a square
-- when the aspect ratio is above 1, the width is longer than the height
-- when below 1, height is larger than width
1 Like

oh god yes that makes sense

I’ll try using that when I get back, its probably gonna be tough though

Thank you so much

I was able to do this using your explanation, these values gave me the best results

Camera = workspace.CurrentCamera
AspectRatio = Camera.ViewportSize.X / Camera.ViewportSize.Y
IsSquare = (AspectRatio < 1.7 and AspectRatio > 0.9)
1 Like