Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by mChapuis · Aug 18, 2019 at 12:01 AM · cameramobileresolutionfov

Camera FOV and Distance based on mobile screen size

I want to change the height and the FOV of the camera based on the mobile resolution.

The issue is that 1- I am not excellent in math and 2- Some information is missing for me to find the missing pieces. I know one angle and one side, but I need more than that to know how to set the angle FOV and the correct height.

From the picture attached, I know the camera is perpendicular to the screen (so a 90 degree angle) and I can find one side of the triangle by getting the Screen.width/2.

Any idea how I can solve the problem?

alt text

stackoverflow.png (71.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Namey5 · Aug 18, 2019 at 09:00 AM

What exactly is the relationship between the camera's height and field of view? We need one to calculate the other, so unless there is a specific relationship it would be easier to define one and find the other relative to that, i.e.

 //Let's say the height is at a constant 10
 float height = 10f;
 
 //Now that we know the side lengths of the right triangle, we can find the angles using trigonometry
 float width = Screen.width * 0.5f;
 float fov = Mathf.Atan (width / height) * Mathf.RadToDeg * 2f;
 camera.fieldOfView = fov;

The basic idea is that;

 //Where a is the angle we are trying to find
 tan(a) = oppositeSide / adjacentSide
 //In our case, the opposite side is 'width' and the adjacent side is 'height'
 //If we want to find the angle 'a', we can use the inverse of the tan function - arctan (atan)
 atan(tan(a)) = a
 //But tan(a) = opp / adj as we saw earlier, so we can find the angle that way
 atan (width / height)

Then to find the field of view, we convert from radians to degrees and double the angle. Now that we know the field of view, you can adjust the height with whatever ratio you want relative to the fov.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mChapuis · Aug 18, 2019 at 02:14 PM 0
Share

That's exactly what I was looking for. Thank you :)

avatar image UnityGuy1717 · May 17, 2020 at 09:10 PM 0
Share

Hello @Namey5 and @mChapuis I am working on what appears to be a similar issue. I've used the math you laid out in this thread but am wondering what I'm missing.

I first specify the "height" which, if I understand correctly, is the distance between the camera and the player/map (not the height of the screen in pixels). This distance uses world units (aka uses values from translate.position) so perhaps this needs to be converted?

I attempted to use the formula you showed above but I'm getting FOVs which are either way too far zoomed out or way too far zoomed in.

To make sure I'm clear in my goal: No matter the device resolution I'd like to show the same amount of world map but zoom in or out depending on the device resolution.

Any pointers would be greatly appreciated!!

avatar image Namey5 UnityGuy1717 · May 18, 2020 at 12:25 AM 0
Share

Height is just a scaling factor to deter$$anonymous$$e the bounds of the screen. If you want to use a world-space height, then you will need to scale the resolution appropriately;

 //Assu$$anonymous$$g default width of 1080 pixels, where 'contentWidth' is the world-space size of the content you want to show
 float width = (Screen.width * 0.5f / 1080f) * contentWidth;

However, that isn't really what the above is for to begin with. The field of view is by default dependant on aspect ratio, not resolution, therefore the content on screen should stay the same regardless of resolution so long as your aspect ratio is the same.

avatar image UnityGuy1717 · May 18, 2020 at 06:09 AM 0
Share

Thank you so much for the quick reply! Have it working now :) VERY much appreciate it!

avatar image
0

Answer by UnityGuy1717 · May 20, 2020 at 12:15 AM

@Namey5 Upon further investigation I realized that my implementation fixed the horizontal size so it's the same across screen resolutions but the vertical is not remaining constant. I found this article which led me to current approach, but I'm still having trouble getting the camera content to remain consistent across resolutions. (https://answers.unity.com/questions/778670/fixed-width-relative-height-on-different-aspect-ra.html)

Is it possible to fix the width and height of camera view so that the experience is the same across devices with different aspect ratios? Is a border/pillbox approach needed? Again, thank you very much for your time!!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

216 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Different camera views in different devices 4 Answers

Camera "Don't Clear" flag doesn't work on Android ? 1 Answer

Adjust the exposure of phone camera manually 1 Answer

Camera viewport should be square and pixel-perfect, regardless of player aspect ratio. 0 Answers

Adjusting Camera Z Position by Resolution (Canvas Size) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges