Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Martin575 · May 26, 2014 at 11:22 AM · camerarotationjavascripttransformequal

Make camera 1 transform equal to camera 2 transform

I have asked this before on here and multiple other sites, but no one has answered yet.

I made this Camera Switch script for the 2 cameras I use (They're both First Person) but when I'm looking straight up and switch to the other camera, the other camera is still looking straight forward or whatever direction I was looking at the last time I used camera2.

So how do I make the rotation of camera 1 to be equal to camera 2 and vice versa when I change my cameras?

This is my javascript:

 var camera1 : Camera;
 var camera2 : Camera;
 var sound1: AudioClip;
 var sound2: AudioClip;
 var sound3: AudioClip;
  
 
 function Start () {
     camera1.gameObject.SetActive(true);
     camera2.gameObject.SetActive(false);
         SwitchCameras();
     }
  
     function Update () {
     //right mouse button
         if(Input.GetMouseButtonDown(1)) {
            SwitchCameras();
         }
    }
    
    function Playsound(){
            audio.PlayOneShot(sound3);
    
    }
    
     function SwitchCameras(){
         if(camera1.gameObject.active == false){
             animation.Play("putUp");
             yield WaitForSeconds(0.25);
             audio.PlayOneShot(sound1);
             camera1.gameObject.SetActive(true);
             camera2.gameObject.SetActive(false);
         
         }
         else {
             camera1.gameObject.SetActive(false);
             camera2.gameObject.SetActive(true);
             audio.PlayOneShot(sound2);
         }
     }
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 Chris_Dlala · May 28, 2014 at 12:26 PM 0
Share

Can you clarify, do you want 2 cameras always at the same point/rotation and switch which one is rendered?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Chris_Dlala · May 26, 2014 at 04:21 PM

Hi, you can get any Monobehaviour's transform to get access to the GameObject's position, rotation and scale.

 camera1.transform.position = camera2.transform.position; // Set camera1's position to that of camera2
 camera1.transform.rotation = camera2.transform.rotation; // Set camera1's rotation to that of camera2

I'm not much of a JavaScript coder but here is an untested function to move a camera to the same position and rotation as another:

 function MoveCamera( camera : Camera, sourceCam : Camera)
 {
     camera.transform.position = sourceCam.transform.position;
     camera.transform.rotation = sourceCam.transform.rotation;
 }

I hope that helps =)

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 Martin575 · May 27, 2014 at 05:28 PM 0
Share

I don't think it works or I implemented it wrong. Either way, I didn't get it to work. :(

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

21 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

Related Questions

Move an object toward an angle in 2d space 0 Answers

Rotating gameobject after mouselook 0 Answers

I need help with camera movement and rotation. 1 Answer

How to make Camera position Independent of its Rotation? 1 Answer

nullifying targetObject after a Smooth LookAt Transition 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