Search Unity

How to use Horizontal Field of View in unity.

Discussion in 'Community Learning & Teaching' started by Cynicat, Nov 17, 2014.

  1. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    To put it simply. this can cause ripping of the hair. a lot.
    so here my loyal subjects is the code required.
    Code (CSharp):
    1. public static float HorizontalToVerticalFOV(float horizontalFOV, float aspect) {
    2.         return Mathf.Rad2Deg*2*Mathf.Atan(Mathf.Tan((horizontalFOV*Mathf.Deg2Rad)/2f)/aspect);
    3.     }
    hopefully this helps some people. pass it the horizontal FOV you want and the camera.Aspect of your camera and it should work.
    now you have 2 ways of working with FOV.
    if i have one request it is that you add an FOV slider that goes to 110 at least into your game. if you really want to be a baller add an option to use either horizontal or vertical fov.
    happy FOVing! =3
     
    Spoken_OS, grae22 and gcard28 like this.
  2. grae22

    grae22

    Joined:
    Oct 27, 2015
    Posts:
    1
    Nice. Works great.
     
    Spoken_OS likes this.
  3. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    I'm glad! good luck. =3