Mobile screen sizes changing camera distance

Any ideas how to prevent the camera changing distance while adjusting the viewport. I’ve heard UE4 tries to keep the FOV the same or something, l don’t know. If someone could link me to a video or give a rough idea on how to prevent this. And please don’t suggest a fixed aspect ratio as this is for mobile and many resolutions would be used.

2 Likes

Anyone have any examples, links, concepts? This is getting urgent now. This must be extreamly simple given the large majority of mobile games that would require this set up.

UE4 keeps the same field of view horizontal regardless of the width of the viewport. So a taller viewport will give the illusion of zooming out but in reality all it is doing is adjusting the horizontal frame to keep the save FOV. It is not really moving the camera or anything else.

Made this quick image to illustrate:

You can counter it using the Aspect Ratio (A.R.)to calculate the Field of View. For example:

  • Take the formula for aspect ratio AR = HorizontalRes/VerticalRes → AR is a float.
  • FOV is a const float defined by you.

Now we can do this using the numbers of the image above:

  • AR * FOV = CameraFOV

So now our field of view will adjust like so:

So what this is telling us is it is 1.339 wider horizontally and even though the aspect ratio vertically is 0.74963, we want to limit it to 1.0 so we don’t go zooming in way more than we should. Know that we know this we can:

  • For horizontal phone, a field of view of 90 → 1.3339 * 68.4713 = 90 and for a vertical phone → 1 * 68.4713 = 68.4713.
    – You’ll need to clamp AR to a minimum of one so for when the height > width, the camera doesn’t keep lowering the FOV.
  • Where did 68.4713 come from?
    – AR * FOV = CameraFOV → FOV = CameraFOV / AR
    – 1.3339 * X = 90
    – X = 90 / 1.3339
    – X = 68.4713

To be clear: I have not done this specifically, but the math should work. I’ll test it out and share some blueprints later.

Hope this helps.

2 Likes

That makes a lot more sense. @pezzott1 l really do appreciate the time taken, especially as l personally bugged you for an answer. I’ll test it out soon. Thank you.

1 Like

Truth is all that gibberish I did above will only give you an approximation, still it might work for what you want.

I was actually hoping to adjust the cameras field of view leaving everything covering same screen space.

Idk yet if it’s the perspective / lens distortion or the FOV not being linear that won’t let me achieve the effect I want without moving the camera.

Figured it out…

The blueprint:

Proof:

This can also create some funky effects:

Explanation:

Now I can finally sleep. :sleepy:

3 Likes

Well holy s*** man. You’re right about your earlier answer, it worked, but this looks superior, exactly what l wanted. Going to take a minute to wrap my head around and implement into my game, but thanks a lot. I’ll update the forum when l do it. I sure you’ve helped a lot of people who will come across this.

1 Like

I can’t seem to get my camera to work correctly. I don’t think it is anything you have done, I’m pretty new to UE4. Would you mind sharing the file you used for your example, maybe l can get mine working from there. Ugh UE4 is so irritating how it doesn’t automatically adjust the camera so the player is always on the screen.

Post a screenshot of how you set up the camera.

I’ve attached the camera component to the player, which moves along with the player as this is an endless runner style game.

Then the blueprint you posted on the player blueprint referencing the camera running from the event tick to update in case the viewport is resized.

And the camera settings are below, must be missing something.

The result is the camera changing its FOV from 0 to 41 every tick, so confused.

Rather than using the line trace, get the distance from camera to capsule component.

1 Like

I don’t know how that wasn’t obvious to me haha. It’s working perfect now. Bloody legend mate.

Thanks for your detailed answer!