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 weenchehawk · Aug 06, 2013 at 01:12 AM · transformmultiple camerastransform.parent

How can I create multiple camera locations.

I'm working on a game which has vehicles, and each vehicle can have multiple camera locations. I would like to do something like the following:

 Vehicle
   CameraRig
       FrontCamera
       RearCamera
       LeftCamera
       RightCamera

Obviously enough this is my transform tree for the vehicle, each of FrontCamera, RearCamera, LeftCamera, and RightCamera have their own position & rotation for where I want the camera locations on the vehicle. To place the camera there I simply connect my MainCamera transform to whichever CameraRig node I like, using

   MainCamera.parent = Vehicle.Find("CameraRig/" + CameraName);

This actually works fine, except in the camera the view doesn't change. This seems to be because MainCamera.position & MainCamera.rotation are being updated (automatically ??) for me as I change it's parent. If I re-set MainCamera.rotation and MainCamera.position to 0,0,0 after updating it's parent then the camera view shows the correct view (Front, Left, Right, Rear etc.).

My questions are :

  1. Why does my MainCamera position & rotation change when I update it's parent ?

  2. How can I stop it (without doing a MainCamera.position = after re-setting it's parent) ?

  3. Is there a better established way of implementing multiple cameras ?

Any help very gratefully received.

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
1
Best Answer

Answer by Adamcbrz · Aug 06, 2013 at 04:45 AM

1) what you are seeing is the difference between local postion and world position. The world position doesn't change when you parent a transform but the local position is local to its parent.

2 ) I think you are out of luck on this one. I don't know a way around not resetting the position and rotation. But it's not that difficult if you use localPosition an localRotation. Just set them to zero and you match the parent.

transform.localPosition = Vector3.zero;

transform.localRotation = Quaternion.identity

3 ) this seems like a good approach. If you are not building for mobile and don't need to optimize you could have multiple cameras and just disable the ones you aren't using. But I think your current approach is best.

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 weenchehawk · Aug 06, 2013 at 05:40 PM 0
Share

Thanks for the answer Adamcbrz

To be honest I expected that local geometry was the culprit, I think I just wanted to hear otherwise.

In fact I had the multiple camera approach done first, but I have multiple network players - each model with a CameraRig, the cams on all models get tagged $$anonymous$$ainCamera (even though they may be a remote player's model) now I'm adding more cam's to implement a radar & a remote view of a target. It's just too many cam's per model & I decided I needed to simplify.

I guess I'll just set localPosition & localRotation as I switch cameras, although it guves me an eye twitch to do it.

Thanks again.

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

16 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

Related Questions

problems parenting a gameObject to another upon instantiating when same name exists 1 Answer

undoing parenting of object's transform 1 Answer

transform.parent not working 3 Answers

Transform.parent returns only null 1 Answer

parent.transform creates new game object 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