Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How do I make the camera obey me?

Discussion in '2D' started by cbfunky, Sep 14, 2020.

  1. cbfunky

    cbfunky

    Joined:
    Sep 11, 2020
    Posts:
    24
    Hello peeps, unity newbie here with what is probably the stupidest question, but I've been stuck at this for hours now and googled my head off, I just can't figure this one out:

    I have a 2D game (actually, doing the TicTacToe tutorial) and I cannot figure out how to tell the camera "this rectangle, this is what I want you to show"

    The tutorial itself mentions nothing of the camera, but it seems to be for an older version of unity (I'm on 2019.4).

    Imagine a square 3x3 grid. Now, initially, the camera cut off the top somehow. I "fixed" that by changing the game view from 16:9 to free aspect and that "worked".

    Over the course of the tutorial, you add more stuff to the game, one being a button on top of the 3x3 grid. And now that button is being cut off and I just can't figure out how to reposition/reframe the camera to make it show exactly the area of screenspace that I want it to show.

    I have already figured out (maybe incorrectly?) to set the canvas render mode to "Screen Space - Camera" and link in the Main Camera - but how to I just simply change the camera box?

    I can't seem to figure out how to set a resolution anywhere, setting a resolution in the player settings does nothing to the camera and neither does scaling the camera.


    camera1.PNG
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @cbfunky

    I would recommend you read camera and UI Canvas documentation several times. Also experiment how changing aspect ratio affects your viewport. This is something you won't usually find in tutorials.

    Unity is a 3D engine, it doesn't simply render some 1920x1080 pixel screen with "flat" sprites and UI elements like some old 2D engines might do, instead you have camera and you'll have to place the camera (ortho or perspective) so that your objects in 3D space are visible in front of it.

    For example, if your Tic-Tac-Toe board grid is now 3x3 units in size and you placed your camera OK you can't simply change board size and expect your camera to somehow show the whole board. You'll have to reposition camera either manually or automatically with some script.

    UI usually covers the whole screen if you use Screen Space Overlay / Camera Canvas (forget World Space Canvas for now) but UGUI canvas supports other methods of placing UI over screen - See Canvas Scaler documentation.
     
  3. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
    Set your Canvas Render Mode to “Screen Space - Overlay”.

    In Game Window, enable Maximize On Play.

    When you enter Play Mode, do you then see everything that you have added to your game?
     
  4. cbfunky

    cbfunky

    Joined:
    Sep 11, 2020
    Posts:
    24
    So, using Screen Space Overlay does show me the whole Canvas, but: it doesn't show me the area that I want to show. I initially thought it adheres to whatever resolution I set in the settings, but that doesn't seem to be the case and I see no way to change the aspect ratio. Right now it's in a weird not-quite-4:3 format and I would like it to be a bit longer.

    I thought, since the camera matches the canvas, all I need to do is change the canvas size, but now with the "Screen Space" setting, any transform properties on the canvas are locked - and the camera has no transform settings that I can see. The documentation makes it sound like the viewport rect W/H properties define width and height, but changing those does nothing. I'm still pretty much stuck with the camera as it is :(
     
  5. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @cbfunky

    "So, using Screen Space Overlay does show me the whole Canvas, but: it doesn't show me the area that I want to show."


    I think you should watch some tutorials and read the docs - UI doesn't control render camera... your camera placement and FOV defines what part of your scene you see in camera. Screen space camera only fits UI to camera frame / screen and renders it in front of scene view.

    Orthogonal camera has a size setting. If you are using Perspective camera, then move/rotate it and optionally adjust FOV. And of course you can move ortho camera too.
     
  6. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
    Canvas Scaler:

    Set your UI Scale Mode to “Constant Pixel Size”.