- Home /
camera or viewport
the two rectangles are for player one & two, a frog character is in the bottom center of each window when they jump they move up and down and the level moves, how do I setup cameras and viewports to accomplish this??
Answer by MoonBoop · Oct 30, 2019 at 10:55 PM
If what you need is split screen, then you can set up two cameras in the scene and have them render to half of the screen each by using the view port rect variables.
if you set the width of each camera to 0.5, and then set the x coordinate to 0.5 in viewport rect, you will get two cameras each rendering to half a screen each like this.
but since I think you want it to look more like the diagram you've provided, you can adjust the width and height of each camera to suit your layout. This will leave some empty screen space, but you can have a gui overlay this blank screen space
Answer by Rocketman_Dan · Oct 30, 2019 at 11:47 AM
You need to add 2 more cameras besides the main one. Set these extra two's render target to two render textures. You wll set each render texture to a material and apply each material to a square. Remember to set the material shader to unlit texture. The main camera points at both panels. The viewport is just the space that is viewable through a camera.
You can make the camera follow the players by making the cameras children of the player charactersin the hierarchy. Make sure your camera aspect ratio fits your render quads or else it will look streteched. Play with your camera settings till you get something that looks good to you.
Ok, lets pretend this is new to me, I've never used any of the functions you talking about, if you could point me to any tutorial of link of any kind as to how to setup a render texture and render my output to it i'd appreciate it cos you lost me in the second sentence!
Thx
While using rendertextures is a solution, it adds unnecessary overhead, requires additional GPU memory and requires render texture support from the target device. Since you can set a viewport area for each camera you can simply set a smaller viewport rect for each sub camera so they only render to their respective area. Also ensure that you set the camera "depth" of your sub cameras to a higher value than the main camera. The main camera usually has a depth of "-1". So since the two viewport cameras do not overlap each other you can set both depth values to "0".
Your answer
Follow this Question
Related Questions
Clamp camera to multiple on-screen players 0 Answers
Second Camera Position on Viewport to UI Element Position on Screen 2 Answers
Is it possible to shift the camera viewport? 3 Answers
Unable to see proper view in viewPort 0 Answers
Two cameras rendering to same viewport rect sometimes causes lower camera to render incorrectly 1 Answer