Hello Guest

Author Topic: Working with multiple cameras  (Read 5022 times)

aschearer

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Working with multiple cameras
« on: May 31, 2013, 12:32:56 pm »
Hi, I'm new to Unity and the 2D Toolkit and am trying to figure out how everything fits together. I have a game which I want to run at different resolutions as long as they're 4:3. It seems like tk2dcamera's Overrides might help, but I'm not sure how to make things work when using multiple cameras.

In my case I have three cameras:

  1. Main Camera draws the background and most of the game parts
  2. Board Camera draws just the game's board. I did this so I could clip elements which are not on the board (for instance the tiles which are pushed up from below the board)
  3. UI Camera draws menus which appear over the board but may extend past the board

When I try adjusting overrides for each camera things are shifted to the center of the screen, etc. so not quite right. I'd appreciate any guidance on how to tackle this problem -- and possibly how to simplify my camera set up...

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Working with multiple cameras
« Reply #1 on: May 31, 2013, 02:41:10 pm »
If you only support 1 aspect ratio, then just using any ortho camera should be fine - you won't need any special logic for normal orthographic cameras to scale to fill the screen, and especially so since the aspect ratio is constant.

The tk2dCamera will work, but will need the default override added.

To make it work with multiple cameras -
1. Set up depth on the cameras - the values should increase in the order the cameras draw.
2. Make sure your 2nd and 3rd cameras don't clear color - just depth, or nothing.
3. Set up layers on objects, and then culling masks to ensure each camera can only see what its meant to.

That should be it really.
If you're using tk2dCamera, you can link the 2nd and 3rd camera to the first, so you will only need to set up overrides on one.

aschearer

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Working with multiple cameras
« Reply #2 on: June 06, 2013, 07:58:29 pm »
Thanks I've almost got it working as I want. Can you expand on "linking cameras"? As it stands when I play at a lower resolution (but same aspect ratio) the secondary cameras do not seem to pick up the main camera's override.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Working with multiple cameras
« Reply #3 on: June 06, 2013, 09:41:02 pm »
I mean the "inherit settings" field on the inspector.
You link secondary cameras to this. The overrides will be picked up from the default one.

If you don't have this field, then you're probably on an older version...