Screen is 2 cameras with each different properties.

Hello everybody!

First of all, Merry Christmas!

And now to the point :
I want to make a game (yeah Cliché beginning) and I want the main character (1ST-Person camera) to be split in 2.
I mean it in a sense of left eye right eye.
So with the left eye you see like a human (it’s a horror game) and the right like a camera.
I want each eye to see different things.
Like in the left part of the screen I see ghosts, while on the right part I do not see them.

I know I can make the screen split in two with Screen.width/2. But now the question. How should I make it? I mean the 2 camera’s.
Make 2 Camera’s and give them each another tag?
I honestly do not know how to begin, yet I am all fired up with coal from Santa, and I want to do it.
Both the eyes have to be controlled by player 1, so it’s not going to be a multiplayer game.
Don’t mind the controls, I can get that done. The problem is with the camera’s.

And for that I need your help.

So, thanks in advance, and have a nice day!
Daniel Nowak Janssen

What you will need is called a scissor rect as talked about in this other question How do I render only a part of the cameras view? - Questions & Answers - Unity Discussions

In a test scene, the steps I followed to get this working were:

  1. Create a new layer to hold your invisible objects. (Edit->Project Settings->Tags and Layers)

  2. Create an empty game object to use as a parent for your two cameras, this will allow you to move them around as if they were one.

  3. Move the default camera in the scene to be a child of the empty game object. Make sure that the transform of the camera is at (0, 0, 0). In the inspector, click on the Culling Mask and uncheck the layer you want your invisible objects to be on. Make sure the Depth is set to 0.

  4. Add a 2nd camera to the scene and make it a child of the empty game object. make sure the transform is the same as the first camera. In the inspector, make sure the Culling Mask is Everything and set the Depth to 1. Remove the Audio Listener component from this camera or unity will give you errors about having 2 in the scene.

  5. Create a new c# script and name it Scissor. Copy and paste the code below into it. Note that this is the same code as in the question I linked, but changed a little because it wasn’t running in Unity 5 since they removed the camera shortcut in favor of using GetComponent.

    using UnityEngine;
    using System.Collections;

    public class Scissor : MonoBehaviour {
    public Rect scissorRect = new Rect (0,0,1,1);
    private Camera _camera;

    void Awake(){
    _camera = GetComponent();
    public static void SetScissorRect( Camera cam, Rect r )
    if ( r.x < 0 )
    r.width += r.x;
    r.x = 0;

    	if ( r.y < 0 )
    		r.height += r.y;
    		r.y = 0;
    	r.width = Mathf.Min( 1 - r.x, r.width );
    	r.height = Mathf.Min( 1 - r.y, r.height );			
    	cam.rect = new Rect (0,0,1,1);
    	cam.ResetProjectionMatrix ();
    	Matrix4x4 m = cam.projectionMatrix;
    	cam.rect = r;
    	Matrix4x4 m1 = Matrix4x4.TRS( new Vector3( r.x, r.y, 0 ), Quaternion.identity, new Vector3( r.width, r.height, 1 ) );
    	Matrix4x4 m2 = Matrix4x4.TRS (new Vector3 ( ( 1/r.width - 1), ( 1/r.height - 1 ), 0), Quaternion.identity, new Vector3 (1/r.width, 1/r.height, 1));
    	Matrix4x4 m3 = Matrix4x4.TRS( new Vector3( -r.x  * 2 / r.width, -r.y * 2 / r.height, 0 ), Quaternion.identity, );
    	cam.projectionMatrix = m3 * m2 * m; 	
    // Update is called once per frame
    void OnPreRender () 
    	SetScissorRect( _camera, scissorRect );


  6. Add the new script to your 2nd camera. In the inspector, change the Scissor Rect of the script to w=0.5 and h=1. This will set the view port to the left half of the screen.

The only other thing you have to remember to do is put all the objects that are invisible on the special layer you created. They should only be displayed in the left half of the screen. Hope this helps.