Search Unity

2 cameras running the same time

Discussion in 'iOS and tvOS' started by mikolo, Mar 30, 2010.

  1. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    Hello,

    i`m programming a jump and rund 3d game with Camera Relative Control.

    I want to have a second camera running the same time...may be if it is possible?

    The second camera should show like a bird from the top and should displayed on the right side on the Main Screen. The Player has got an Overview, where he and the enemys are.

    Is this possible with 2 Cameras or do i have to programm otherwise?

    many regards
     
  2. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    It is certainly possible to have multiple cameras at once. There are a couple things to know that will help with this:

    - Cameras have a "depth" property. This determines which order the cameras will draw. The camera with the highest depth will draw on top of the camera with the lowest.

    - Clear Flags are important when dealing with multiple cameras. This basically says what to do with the empty space around whatever the camera is drawing. The foreground camera should be set to Depth Only. This will allow you to see the contents of the background camera.

    - Culling masks are also useful. These allow you to control what content gets rendered with which camera via layers.

    I hope that helps. Check out the camera page in the documentation for more info.
     
  3. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    Thanx the main principle i understand but i dont know how to begin. Do you have a simple script for me?

    regards
     
  4. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    No scripts necessary. Try this setup.

    Camera 1 (foreground):
    Depth: 1
    Clear flag: Depth only

    Camera 2 (background):
    Depth: 0
    Clear Flag: Solid Color

    Now just point camera 1 at the stuff you want in the foreground and point camera 2 at the background.
     
  5. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    OK this works... but i want a little 2D Window on the main screen where exactly can see the game from the top with a camera. Like a birdview in a window.

    The normal 3D Camera Relative should run also on the hole main screen.

    I hope you understand?

    regards
     
  6. Randy-Edmonds

    Randy-Edmonds

    Joined:
    Oct 10, 2005
    Posts:
    1,122
    I've done what you want on the iPhone like this....

    1. With the gameobjects you want to appear on the "radar", each one needs to have a child gameobject that is something like a simple sphere. No colliders or physics on the sphere.

    2. These spheres need to be assigned a unique tag... maybe name it "RadarViewOnly".

    3. On the Main Camera (the camera that is used for your regular game play), change the culling property to NOT include "RadarViewOnly".

    4. Now position a new Camera (the radar camera) up high, directly above the Main Camera, and have it looking straight down. Set this camera's culling property to ONLY include "RadarViewOnly". And set the clear flag to Depth Only.

    5. If you want the radar view to seem to appear in a window. You should place a 2d plane, with the a texture that you want to use as the window, as a child of the radar camera, set it's tag to "RadarViewOnly", and have it positioned facing the radar camera and far away.


    That should do the trick.
     
  7. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    So you want two cameras rendering the same scene from a different angle, and one to only take up a corner of the screen? Also doable. You will want to set the top-down camera to a higher depth and use the camera's Normalized Viewport Rectangle to trim it down to fit in one corner. Again, I suggest you read the manual entry about cameras.
     
  8. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249

    Thanxxx i understand now and i tryed like you wrote.
    It works! Now i will try this with a plane as window.

    Thanxx to all.. maybe another question comes :)
     
  9. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    no no... i cant do it :cry:

    how can i produce the hole scene in the little Plane in the right corner?

    I have a camera who films the hole game area..and in this camera object as children there is a Plane. The Plane i give the position to the rigth corner.
    The camera only shows the enemys with culling Mask (RadarView). That work fine. But the only step to produce it on the plane? This is what i dont understand now. Also i tryed to change the values of Normalized View Port Rec... but i dont understand.

    Thanx for help again
     
  10. mikolo

    mikolo

    Joined:
    Nov 27, 2009
    Posts:
    249
    OK, I think this is the best solution for a radar:

    http://www.unifycommunity.com/wiki/index.php?title=Radar

    But i am also happy with camera solutions. Please post here some scripts where you can real watch the game like radar in a life camera in a little window next to the main game.

    Thanks
     
  11. stunriver

    stunriver

    Joined:
    Mar 5, 2010
    Posts:
    10
    Hi I tried to do Normalized Viewport Rectangle, in game view it looks okay, but when I build the game it won't show the second camera(MiniMap)I already make the Mini Map depth 1 and the Main camera depth 0, and still doesn't work, I also clear flags the Mini Map with depth only, and the Main camera Solid Color and still doesnt work, any idea?
     
  12. raviraj_vdy

    raviraj_vdy

    Joined:
    May 14, 2009
    Posts:
    309
    @mattimus awesome solution, Thanks it really saved the day.
     
  13. JeiAzul

    JeiAzul

    Joined:
    May 22, 2015
    Posts:
    1
    How make 4 cams on same scene, each one for view rifgth, left, front, back...?
     
  14. 0000sir

    0000sir

    Joined:
    Jul 23, 2015
    Posts:
    1
    Hey man, This is what I'm looking for! do you solve it? Let me know pls.
     
  15. ArmyOfCamels

    ArmyOfCamels

    Joined:
    Feb 2, 2015
    Posts:
    3
    Create those 4 cameras and set the viewport rect to 0.5-0.5 in size and the positions accordingly (0-0 0.5-0 0-0.5 0.5-0.5)
     
  16. Hybris_Team

    Hybris_Team

    Joined:
    Oct 17, 2015
    Posts:
    114
    That Depth value just saved me so much time trying to figure out how to get UI to render without the post processing stack THANK YOU.
     
  17. team_enso

    team_enso

    Joined:
    Dec 29, 2015
    Posts:
    5
    How did you solve this exactly?
     
  18. Hybris_Team

    Hybris_Team

    Joined:
    Oct 17, 2015
    Posts:
    114
    Hey I will take a look at this, I cant remember exactly what I did. I'll post screenshots of how I have it set up later when I'm at the crib
     
  19. nurulshahida2012

    nurulshahida2012

    Joined:
    Mar 1, 2021
    Posts:
    1

    Hey man, This is what I'm looking for! do you solve it? Let me know pls.
     
  20. Petras-Unity

    Petras-Unity

    Unity Technologies

    Joined:
    Oct 7, 2020
    Posts:
    25