- Home /
Rendering 2 Cameras without using Clear Flags
So the general concept I'm going for is a form of controlled teleportation. Game is 1st person, standard WASD controls, mouse look on capsule; nothing special.
I want a 2nd camera in the world to render to a plane that has a fixed position in the world (think a TV screen). This is typically done using a Render Texture. My 2nd camera isn't currently rendering the to plane. I just see gray, unsure why.
I want to remotely control the 2nd camera using the arrow keys, and have its view drawn to the plane. My WASD Controller script uses the Input axes, so I'll likely have to write a separate script to control the remote camera, but I should be able to handle that no problem.
When the character capsule walks through the plane (trigger collider enter), the character should teleport to where the remote camera is looking. I want the 2 cameras to "swap," essentially, and the travel plane to appear behind the character at his new location. This can likely be done with a position check and handoff, so nothing crazy complicated there, either.
All the tutorials and code I've seen for rendering multiple camera at the same time in Unity all use the Clear flags OR overlay both camera views to the main display. Neither of these will work for what I'm trying to do. I need the remote camera to render everything, even the skybox, so the player can understand where he is traversing to before he teleports there.
Is this even possible? If so, how could I accomplish it?
Secondly, any reason the render texture might not be drawing properly? I've adjusted the Depth value of both cameras and neither Depth(camera1) > Depth(camera2), Depth(camera1) == Depth(camera2), nor Depth(camera1) < Depth(camera2) have allowed the remote camera to render onto the plane. Any ideas on what's keeping it from drawing?
another way to think of this, is ins$$anonymous$$d of a render texture, have 2 cameras on top of eachother that render different scene objects with a "portal" (your current render texture plane) as a clear flag for the top camera. if you think about it as layers, the top most camera wouldnt be drawing that planes space since its cleared, leaving the bottom camera able to render there. since the bottom layer camera sees the scene differently (draws only specific layers) it will render a different set of game objects inside that plane. idk if thats explained very well. its almost like having 2 photographs of different objects stacked right on top of eachother, but youre punching a hole in the top photograph to see the bottom
since theres 2 cameras rendering, youd be free to do whatever you want with that second camera and when the player walks through your portal, flip the cameras so now the top is the bottom
i dont have much experience with render textures, but it should be pretty straight forward. https://answers.unity.com/questions/477888/texture-showing-camera-view.html https://docs.unity3d.com/$$anonymous$$anual/class-RenderTexture.html
I'm trying to avoid using the clear flags because I want the cameras to render to independent displays, not have some semitransparent overlay of both viewports on the same display.