• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Daniel_Zabojca · Dec 15, 2015 at 02:49 AM · camera3dcamera-movementcamera rotatecamera-look

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 t$$anonymous$$ngs. Like in the left part of the screen I see ghosts, w$$anonymous$$le 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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sandeepsmartest · Dec 15, 2015 at 05:34 AM 0
Share

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by LazyElephant · Dec 15, 2015 at 05:46 AM

What you will need is called a scissor rect as talked about in t$$anonymous$$s other question http://answers.unity3d.com/questions/134413/how-do-i-render-only-a-part-of-the-cameras-view.html

In a test scene, the steps I followed to get t$$anonymous$$s 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, t$$anonymous$$s will allow you to move them around as if they were one.

  3. Move the default camera in the scene to be a c$$anonymous$$ld 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 c$$anonymous$$ld 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 Everyt$$anonymous$$ng and set the Depth to 1. Remove the Audio Listener component from t$$anonymous$$s 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 t$$anonymous$$s 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<Camera>();
     }
         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, Vector3.one );
             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. T$$anonymous$$s will set the view port to the left half of the screen.

The only other t$$anonymous$$ng 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 t$$anonymous$$s helps.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Daniel_Zabojca · Dec 15, 2015 at 08:46 AM 0
Share
avatar image LazyElephant Daniel_Zabojca · Dec 15, 2015 at 08:58 AM 1
Share
avatar image Daniel_Zabojca LazyElephant · Dec 15, 2015 at 12:30 PM 0
Share
Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i make the camera look up and down through keyboard keys? 2 Answers

Jerky 3rd Person Camera Following Movement and Rotation 0 Answers

Rotate Camera to the object 0 Answers

How to have free rotation camera? 1 Answer

camera movments fixed.. character controller without using character controller -.-' 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges