Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Setting a Orthographic cameras FOV to a terrainsize

Discussion in 'Scripting' started by Perillio, Mar 23, 2019.

  1. Perillio

    Perillio

    Joined:
    Feb 4, 2019
    Posts:
    18
    Hello :)

    i want to do a minimap on my own but now im stuck at the point where i need to set the FoV of the camera to a value that it can see the whole "map" (the Terrain im on).

    i already have the X and Y values of the terrainsize, pushed the cam in the middle and 500 above the terrain but now i dont have an idea how to calculate the exact FoV Value as it is not an X and Y system but just a single float.

    Any info how to calculate this with X and Y size ?

    greetings,

    Stefan
     
  2. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    :)
    had to fix this last week.
    You need to set your camera.orthographicSize
    Since that is indeed a single float, you need to take the max of your maps dimensions.
    So, if x >y you take the x, otherwise the y.
    You need to divide that by two.

    so,
    camera.orthographicSize = your max size/2;

    hope it helps
     
    Perillio likes this.
  3. Perillio

    Perillio

    Joined:
    Feb 4, 2019
    Posts:
    18
    Thats it. Perfect :)
    Thank you very much :)