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

Stretch Box to Camera Viewport

Discussion in 'Scripting' started by jtsmith1287, Mar 27, 2015.

  1. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    I'm looking to prevent players from leaving the viewport. I had code handling this but I'm doing some refactoring and adding in more physics. So instead of dealing with that I just decided to make a box scale to the camera's viewport at a specifc z distance. I sat down, cracked the knuckles and though, "Wow I don't have a clue how to do this". I did some googling and nothing is clicking for me based on the 5 or 6 top links I followed.

    Anyone have any pointers?
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. Mathieu_Dossmann

    Mathieu_Dossmann

    Joined:
    Oct 31, 2014
    Posts:
    2
    One of your major problem is the viewport, as it can be modified (i guess?) with the FoV and the resolution, hence resizing accordingly your boundaries box. So each player, with a different screen resolution wouldn't have the same boundaries...
    The only way in that case, would be to ensure having the same screen res, aspect ratio and FoV for all players. (Like games on console -> fixed res and aspect ratio). Especially for multiplayer games where everyone needs the same constraints/boundaries/rules.

    Or you make a box with fixed coordinates, and if the player changes the screen res and/or FoV, you adapt the viewport/camera view to the box by zooming in or out, so the viewport/camera height and width fit the box height or width.