• 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 Bentoon · Nov 16, 2016 at 04:25 AM · c#vrcamera-movement

Having a main Camera rotate other cameras

Hello I have my main camera in a VR scene There are also window that display other scenes with render Textures (I have other cameras rendering to window textures)

I want the main camera movement to and fro to be reflected by the other cameras Rather than Parenting the cameras to the main camera (which almost works but gives too much movement & some weird feedback) I want to do this with script, so

My Main cameras rotations are passed to these secondary Cameras... I have no errors but nothig happens in my secondary cameras...

What am I doing wrong?

MAIN CAMERA: using UnityEngine; using System.Collections;

 public class VRCamMain : MonoBehaviour {
 
     //Storing the main Cameras values to pass to secondary cameras
     //public float VRposX;
     //public float VRposY;
     //public float VRposZ;
     public float VRrotX;
     public float VRrotY;
     public float VRrotZ;
 
 
 
     void Update()
     {
         //Capture  pos & rot
         //VRposX = Camera.main.transform.position.x;
         //VRposY = Camera.main.transform.position.y;
         //VRposZ = Camera.main.transform.position.z;
         VRrotX = Camera.main.transform.rotation.x;
         VRrotY = Camera.main.transform.rotation.y;
         VRrotZ = Camera.main.transform.rotation.z;
     }
 
 }
 

SECONDARY CAMERAS: using UnityEngine; using System.Collections;

 public class VRCamSmall : MonoBehaviour {
 
     // this calls the Main camera Script to get its values
      VRCamMain  _VRCamMain;
     // storing myCamera positions locally
     //private float posX;
     //private float posY;
     //private float posZ;
     private float rotX;
     private float rotY;
     private float rotZ;
     //naming ind camera
     public GameObject myCamera;
 
 
     //these are coming from other script 
     //public float VRposX;
     //public float VRposY;
     //public float VRposZ;
     //public float VRrotX;
     //public float VRrotY;
     //public float VRrotZ;
 
 
     void Start()
     {
         _VRCamMain = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<VRCamMain>();
        //posX= myCamera.transform.position.x;
        // posY=myCamera.transform.position.y;
        //posZ= myCamera.transform.position.z;
        rotX= myCamera.transform.rotation.x;
        rotY= myCamera.transform.rotation.y;
        rotZ= myCamera.transform.rotation.z;
     }
 
     void Update()
     {
         //posX = posX + _VRCamMain.VRposX;
         //posY = posY + _VRCamMain.VRposY;
         //posZ = posZ + _VRCamMain.VRposZ;
         rotX = rotX + _VRCamMain.VRrotX;
         rotY = rotY + _VRCamMain.VRrotY;
         rotZ = rotZ + _VRCamMain.VRrotZ;
     }
 
 
 
 }
 

I Appreciate your help

~be

Comment
Add comment
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

2 Replies

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

Answer by aditya · Nov 16, 2016 at 05:18 AM

There is nothing wrong with this code because there is nothing in this code despite of some variables with some values ... you've just fetched the values from VRCamMain class and did nothing with them, you need to apply these values to your secondary cameras

 secondaryCamera.transform.localRotation = Quaternion.Euler(rotX, rotY, rotZ);

Accept if it did the trick

Comment
Add comment · Show 1 · 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 Bentoon · Nov 16, 2016 at 05:00 PM 0
Share

@aditya Thanks but still doesn't work. I put it in the Update Function, but it doesnt move at all...

It was my novice thinking that putting

          rotX = rotX + _VRCam$$anonymous$$ain.VRrotX;
          rotY = rotY + _VRCam$$anonymous$$ain.VRrotY;
          rotZ = rotZ + _VRCam$$anonymous$$ain.VRrotZ;

in the update function would add the amount that tthe main Camera moved to the second Cameras..? Thanks!

avatar image
0

Answer by Bentoon · Nov 17, 2016 at 03:09 AM

@aditya Almost! I'm Accepting this, although now the camera just Spins Wildly (although it seems to be coming a bit from how I move my head... ) Maybe I need a Fraction of the movement.. leading to stop when I stop moving the Main Cam (head tracking)?

MAIN CAM:

 public class VRCamMain : MonoBehaviour {
 
 
     // capture the Cam initial Pos 
     public float initPosX;
     public float initPosY;
     public float initPosZ;
     public float initRotX;
     public float initRotY;
     public float initRotZ;
 
     //Storing the main Cameras mov values to pass to secondary cameras
     public float VRposX;
     public float VRposY;
     public float VRposZ;
     public float VRrotX;
     public float VRrotY;
     public float VRrotZ;
 
     void Start()
     {
         initPosX = Camera.main.transform.position.x;
         initPosY = Camera.main.transform.position.y;
         initPosY = Camera.main.transform.position.z;
         initRotX = Camera.main.transform.rotation.x;
         initRotY = Camera.main.transform.rotation.y;
         initRotZ = Camera.main.transform.rotation.z;
 
     }
 
     void Update()
     {
         //Capture change in pos & rot minus initial 
         VRposX = Camera.main.transform.position.x - initPosX;
         VRposY = Camera.main.transform.position.y - initPosY;
         VRposZ = Camera.main.transform.position.z - initPosZ;
         VRrotX = Camera.main.transform.rotation.x - initRotX;
         VRrotY = Camera.main.transform.rotation.y - initRotY;
         VRrotZ = Camera.main.transform.rotation.z - initRotZ;
     }
 
 }


SECONDARY CAMS:

 public class VRCamSmall : MonoBehaviour {
 
     // this calls the Main camera Script to get its values
      VRCamMain  _VRCamMain;
     // storing myCamera positions locally
     private float posX;
     private float posY;
     private float posZ;
     private float rotX;
     private float rotY;
     private float rotZ;
     //naming ind camera
     public GameObject myCamera;
 
 
     //these are coming from other script 
     public float VRposX;
     public float VRposY;
     public float VRposZ;
     public float VRrotX;
     public float VRrotY;
     public float VRrotZ;
 
 
     void Start()
     {
         _VRCamMain = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<VRCamMain>();
        posX = myCamera.transform.position.x;
        posY = myCamera.transform.position.y;
        posZ = myCamera.transform.position.z;
        rotX= myCamera.transform.rotation.x;
        rotY= myCamera.transform.rotation.y;
        rotZ= myCamera.transform.rotation.z;
     }
 
     void Update()
     {
         posX = posX - _VRCamMain.VRposX;
         posY = posY - _VRCamMain.VRposY;
         posZ = posZ - _VRCamMain.VRposZ;
         rotX = rotX - _VRCamMain.VRrotX;
         rotY = rotY - _VRCamMain.VRrotY;
         rotZ = rotZ - _VRCamMain.VRrotZ;
         myCamera.transform.localRotation = Quaternion.Euler(rotX, rotY, rotZ);
     //    myCamera.transform.localPosition = Quaternion.Euler(posX, posY, posZ);
     }
 
 
 
 }
 
Comment
Add comment · 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

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

253 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Main Camera movement controlling others, rendering to texture 0 Answers

Controllers are jittery with the HTC Vive. 0 Answers

I only rotated X, but Y and Z are shifting as well when I play the game. 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