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 xwheat32x · Mar 02, 2014 at 05:16 AM · cameracamera-movementcamera rotateteleporting

Teleporting a camera to a camera

Basically, I want a camera to teleport to the exact same position and rotation as another camera. How can I do this in JavaScript?

I have function Update that checks for when a player presses a certain key, and when that key is pressed, I want the camera to teleport to the main camera.

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

1 Reply

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

Answer by robertbu · Mar 02, 2014 at 05:17 AM

I think you just want:

 transform.position = Camera.main.transform.position;
 transform.rotation = Camera.main.transform.rotation;

This assumes you've left the main camera tag as 'MainCamera'.

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 xwheat32x · Mar 02, 2014 at 07:53 PM 0
Share

They're both tagged as main camera though. I have two variables in the script for both of the cameras(cam1 and cam2), so is there a way to use that but it uses the variables ins$$anonymous$$d?

avatar image robertbu · Mar 02, 2014 at 08:38 PM 0
Share

Sure. I'm not sure which camera is which, but let's assume that this script wants to move to the position of cam1:

 transform.position = cam1.transform.position;
 transform.rotation = cam1.transform.rotation;
avatar image xwheat32x · Mar 02, 2014 at 09:04 PM 0
Share

This script isn't attached to either of the cameras. It's on a pause menu script. "cam2" is a camera that doesn't move, so when the game pauses, "cam2" will become the active camera. "cam1" is normally the main camera. So would I write the code like: cam2.transform.position = cam1.transform.position;

avatar image robertbu · Mar 02, 2014 at 09:18 PM 0
Share

You are going to have to get access to the transform of the two cameras somehow. Assu$$anonymous$$g these camera's exist all the time in the scene, the easiest way would be to put two variables in the top of your pause script:

 var cam1 : Transform;
 var cam2 : Transform;

You would initialize these two variables selecting the game object with the pause script in the hierarchy and by dragging and dropping each camera object from the hierarchy on the appropriate variable in the Inspector. Then your code would be:

 cam2.position = cam1.position;
 cam2.rotation = cam1.rotation;

Another way would be to give each camera a unique name and initialize some variables in start:

 private var cam1 : Transform;
 private var cam2 : Transform;

 function Start() {
     cam1 = GameObject.Find("$$anonymous$$ain Camera").transform;
     cam2 = GameObject.Find("Other Camera").transform;
 }

Then you would move and rotate the camera the same way as the previous solution.

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

20 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

Related Questions

How to create a panning, rotating camera with Cinemachine Freelook camera? 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

How to allow camera to complete an upside down rotation while using LookAt() 0 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