• 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
Question by PsychoHead · Sep 17, 2012 at 03:36 PM · camerarotationthird-personfirst-person

How to make two cameras face the same direction?

I basically have two scipts controlling the same camera. One for Third Person, one for first person. When I switch between the two, I want them to face the same direction. My plan was to get the forward vector of one of the cameras and use transform.lookAt on the other, to face that direction, sadly that doesn't work as intended.

Drawing a ray with that method, starting at transform.position works perfectly fine. What do I do wrong?

Comment
proVeritas_vk

People who like this

1 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 Fattie · Sep 17, 2012 at 05:10 PM 1
Share

You have to specify what you mean hyper-clearly.

Should they be looking at exactly the same object?

Should they be looking at exactly the same point, some certain distance away? (Say 5 meters - you'd have to exactly state the meters you mean.)

Should the line of sight of the two cameras be exactly parallel?

There are other possibilities but it's likely you mean one of those. The three I mention are totally and completely different in how you need to approach them. Fill us in !

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by whydoidoit · Sep 17, 2012 at 03:37 PM

Try:

 camera2.transform.forward = camera1.transform.forward;
Comment
proVeritas_vk

People who like this

1 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 PsychoHead · Sep 17, 2012 at 04:21 PM 0
Share

I don't quite understand your tip, and how this should work?

My idea was passing the direction from the 3. Person camera over to the 1. Person camera, converted to world space.

 Vector3 globalForward = Transform.TransformDirection(transform.forward);
 FP_Camera.Instance.setDirection(globalForward);

Afterwards I wanted to adjust the 1. person camera with it's script:

     public void setDirection(Vector3 globalLookDirection)
     {
 
         Vector3 localLookDirection = transform.InverseTransformDirection(globalLookDirection);
         transform.LookAt(localLookDirection);
     }

What's my mistake behind this thought? Like I said, drawing a ray works as intended, but the camera doesn't get adjusted at all.

avatar image whydoidoit · Sep 17, 2012 at 04:25 PM 0
Share

transform.forward is already in world space coordinates - there is no need to transform it. LookAt looks at something (a point in 3d space not a direction). Setting one transforms forward to another ones makes them look in the same direction - but to ensure that Up didn't change you could do:

   camera2.transform.rotation = Quaternion.LookRotation(camera1.transform.forward, transform.up);
avatar image PsychoHead · Sep 17, 2012 at 05:15 PM 0
Share

Okay, it doesn't work. I guess it's some problem with another part of my script, that I haven't thought of yet. After all, it's the same camera, just moved. When I just change it's position, the rotation shouldn't even change, therefor there should not be the need for a new rotation.

I'll just continue searching for the problematic part.

Thank you nonetheless!

avatar image whydoidoit · Sep 17, 2012 at 05:19 PM 0
Share

@fattie is right in the comment above - I might have been too literal in my answer - it's possible this isn't the effect you are looking for!

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

12 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

Related Questions

Player rotation = Camera Rotation 0 Answers

TPS Rotation Camera (similar to WoW or any other mmo) 0 Answers

Need help for player rotation and camera rotation 0 Answers

How to keep the player on the left side o the screen? 2 Answers

How do i combine first and third person views? 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