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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by V4mpy · Oct 30, 2013 at 12:26 PM · camera rotateitweenfollow pathcurved path

Camera always 90 degrees to player (curved path)

Hello togehter,

a friend and me have some issues with our camera movement.

We have a curved path and our player moves along it.

We want that our camera always looks at our player in a 90 degree angle. It should not matter in which rotation or position the player currently is. Additionaly the camera should see the player only from one side.

look at our beautiful pictures for reference (black stuff is path, arrows are camera rotation ):

what we want:

alt text

what we currently have and don't want (green arrows are the correct ones):

alt text

First Solution:

         if (target) {
     
             transform.position = new Vector3 (target.position.x, target.position.y, target.position.z);
             
             if (controllerScript.characterDirection == Controller.Direction.Forward) {
                 transform.rotation = new Quaternion (target.rotation.x, target.rotation.y, target.rotation.z, target.rotation.w);
             }
             if (controllerScript.characterDirection == Controller.Direction.Reverse) {
                 transform.rotation = new Quaternion (target.rotation.x, target.rotation.y - 1, target.rotation.z, target.rotation.w);
             }
         }
         transform.Translate (cameraDistance, cameraYOffset, 0);
         transform.LookAt (target);



This works fine, but in a curve the camera has a strange x-offset. Our camera is not child of the player

Second solution:

The camera is a child of the player. This works fine for one direction, but if we change the direction, the camera changes its rotation, because it is child. This is completely logical, but we don't want this rotation.

Our Question is: Is there a way to prevent the rotation?

We are using iTween. Is there a method we are currently unaware of that could help us?

frage1.jpg (30.6 kB)
frage2.jpg (32.5 kB)
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 Tomer-Barkan · Oct 30, 2013 at 12:30 PM

Making camera a child is the best way to go in my opinion. What you can do, once the player changes direction, move the camera so that it is on the other side.

To change the position of the camera to be the exact opposite of the player from its current position:

 camera.transform.localPosition = -camera.transform.localPosition; // move the camera to the opposite side of the player. Assuming camera is child of player.
 camera.transform.LookAt(camrea.transform.parent.position); // turn the camera so that it faces the player
Comment
Add comment · Show 10 · 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 V4mpy · Oct 30, 2013 at 01:10 PM 0
Share

Thanks! This works fine. We only had a problem with the y axis. Post it here in case someone needs it, too. We solved it this way:

 camera.transform.localPosition = new Vector3(-camera.transform.localPosition.x, camera.transform.localPosition.y, -camera.transform.localPosition.z);    
             camera.transform.LookAt(camera.transform.parent.position);
avatar image Tomer-Barkan · Oct 30, 2013 at 01:23 PM 0
Share

Oh, right, I assumed the localY was 0 (ie the camera was same height as the player) which I see was an incorrect assumption.

avatar image V4mpy · Oct 30, 2013 at 01:51 PM 0
Share

Is there a possibility to have an offset so that i do not look directly to the player but a bit in front of him? Without loosing the 90 degree angle.

Our approach would be to not use LookAt(player); but to rotate the camera with 180 degrees. We simply do not know how to tell that the Quaternion :(

avatar image Tomer-Barkan · Oct 30, 2013 at 01:58 PM 0
Share

Sure,

 Quaternion rotate180 = Quaternion.AngleAxis(180, Vector3.up); // rotate 180 degrees around the Y axis
 camera.transform.forward = rotate180 * camera.transform.forward; // rotate camera 180 degrees
avatar image V4mpy · Oct 30, 2013 at 02:08 PM 0
Share

the sad thing is that we were completly sure that these questions are hard to answer... ^^ it is embarrassing

Show more comments

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

PutOnPath is not working for changing paths. 0 Answers

how to follow curved path? 4 Answers

Changing this code to control camera with keys? 0 Answers

Character moves along pre-defined path / curve 1 Answer

iTween: Cannot cast from source type to destination type. 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