Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 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

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

Try using layers and by assigning culling mask(number of layers each camera sees) to each camera. Select camera ->camera component->culling mask->select the layer of the game objects for which this camera should see. Hope this may help you at a very basic level Nsks

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 this 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 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<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. 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.

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

First of all thank you!

Second of all, What does matrix do in this context? Does it do the arbitrary linear 3D transformations? Can you maybe explain to me what that $$anonymous$$atrix 4x4 does?

Thank you again for your time, And have a $$anonymous$$erry Christmas, $$anonymous$$ Nowak Janssen

avatar image LazyElephant Daniel_Zabojca · Dec 15, 2015 at 08:58 AM 1
Share

I don't understand the details either, but I can give a basic explanation. In Unity, if you resize the camera's view port, it doesn't just cut out the parts of the screen that would be outside the new size, it shrinks the scene down a bit. For instance, if you have a cube in the direct center of the screen and change the camera width to .5, you'll still see all of the cube in the screen, still in the middle of the view port, although smaller. You can test this yourself in the editor.

The three matrices made with the $$anonymous$$atrix4x4.TRS (Translate, Rotate, Scale) change the view port of the camera to match what you would see on just the portion of the screen you want as if the camera view port were still full size.

avatar image Daniel_Zabojca LazyElephant · Dec 15, 2015 at 12:30 PM 0
Share

Somehow, my second camera does not show only the layer I want. I made a new layer called Ghost, and I made one enemy in that layer. But both my camera's see the same enemy, but only the left part of the screen should see the enemy. $$anonymous$$aybe I did something wrong? I do not know, but maybe it is conflicting with my $$anonymous$$ouseLook script. (It makes you move your camera. Here is the script :

     using UnityEngine;
      using System.Collections;

     public class $$anonymous$$ouseLook : $$anonymous$$onoBehaviour {

    public enum RotationAxes

   {
     $$anonymous$$ouseXAndY = 0,
     $$anonymous$$ouseX= 1,
     $$anonymous$$ouseY= 2

 }
 public RotationAxes axes = RotationAxes.$$anonymous$$ouseXAndY;
 public float SensitivityHor = 9.0f;
 public float SensitivityVer = 9.0f;

 public float $$anonymous$$imumVert = -45.0f;
 public float maximumVert = 45.0f;

 private float _rotationX = 0;

      // Update is called once per frame

     void Start()
     {
     Rigidbody body = GetComponent<Rigidbody>();
     if (body != null)
         body.freezeRotation = true;



     }
      void Update () {
    if ( axes == RotationAxes.$$anonymous$$ouseX)
     {
     //horizontal movement
         transform.Rotate(0,Input.GetAxis("$$anonymous$$ouse X") *                                          SensitivityHor, 0);
       }

      else if (axes == RotationAxes.$$anonymous$$ouseY)
     { 
             //vertical movement
         _rotationX -= Input.GetAxis("$$anonymous$$ouse Y") *  SensitivityVer;

        
         _rotationX = $$anonymous$$athf.Clamp(_rotationX, $$anonymous$$imumVert, maximumVert);

         float rotationY = transform.localEulerAngles.y;

         transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);

      }
  else
      {

          //makes it possible to rotate my head
         _rotationX -= Input.GetAxis("$$anonymous$$ouse Y") * SensitivityVer;
         _rotationX = $$anonymous$$athf.Clamp(_rotationX, $$anonymous$$imumVert, maximumVert);

         float delta = Input.GetAxis("$$anonymous$$ouse X") * SensitivityHor;
         float rotationY = transform.localEulerAngles.y + delta;

         transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);

     }
 
 }
  }


I made 2 Camera's and made them children to my $$anonymous$$ain character (a capsule for testing) and still the enemy does not disappear on the right side of my screen. it just stays visible although it should not.

Thanks again for your help, and have a $$anonymous$$erry Christmas. $$anonymous$$ Nowak Janssen.

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.

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

Unity - Dancing Ball World camera following and rotating system 1 Answer

Would anyone teach me how to create camera movement and look controls? 2 Answers

Cinemachine input axis camera movement,cinemachine input axis control with script 1 Answer


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