• 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
0
Question by blitzcloud · Jan 25, 2016 at 12:25 AM · cameraaspect-ratio

What would be the appropriate take on making the camera retain the horizontal space despite the aspect ratio

Side scroller game, things go from right to left. Reaction time is really important so the only choice for tablets and non-16:9 AR devices would be to have black borders. I'd love to avoid that but I don't know if it's something I can easily config or if I have to make a mathematical script for the camera.

In other words, I want that the 4:3 aspect ratio gets to have the same horizontal field of view as the 16:9 version, but of course that wuill translate with being able to see more below and above.

Thanks in advance for the help

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

1 Reply

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

Answer by blitzcloud · Jan 25, 2016 at 12:22 AM

As it seems to be the case in almost every question I create, I found the answer myself (technically, it wasn't even posted).

 static var widescreen:float=1.777777777777778;
 static var fov:float=10;
 
 function Start () {
 getFOV();
 }
 
 static function getFOV (){
         Camera.main.fieldOfView=(widescreen/Camera.main.aspect)*fov;
 }

if i'm testing it on a target 16:9 aspect ratio, I simply put the target FOV and AR declared up there. Then I just run a static function because it otherwise fails where it makes the math to change the FOV according to the new aspect ratio.

This is 100% accurate technically speaking, because widescreen/16:9 equals 1 * desired FOV. That means no changes are made.

If there's another AR like 4:3 it simply divides 1,777/(4:3) which results in 1,333*desired FOV, giving the exact same horizontal FOV, with more spacing on the top and bottom.

Guess there really was an appropriate easy solution. Of course given that I want a perfect scaling I decided to go this way, but it would be possible to make a sequence of IFs to get the known AR of the devices (16:9, 16:10, 4:3, etc), in case we want special placing of the camera or just a custom FOV.

Cheers

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why is the camera aspect ratio broken for the game tab? 0 Answers

Scale Everything In Game to Fit all screen Sizes 1 Answer

Why does my game have letterboxes on the side? 1 Answer

How to force the game to be stretched to fit the screen? 1 Answer

How to set z position for camera to fit game field 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges