Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by esillen · Nov 15, 2014 at 03:10 AM · cameraflip

Prevent camera from flipping when rotating around origo?

Hello Unity Answers! I have a character who moves on the surface of a globally fixed cube. I want the camera to look straight on the character and follow the characters movements by circling around origo and look at the character. I don't want it to rotate the camera if the character rotates etc but just following the movements of the character on the cube. I have implemented this using transform.LookAt(origo) but my problem is that the camera flips when the character has moved so that the camera would have its upward vector downwards in the global coordinates (because of how LookAt is implemented).

I have the following script in my camera:

     void Start () {
             distance_from_origo = transform.position.magnitude;
     game_script_container.GetComponent<Game_script>();
         }
     void Update(){
     goto_position = (game_script.getPosition()).normalized*distance_from_origo;
             transform.position = Vector3.Lerp(transform.position, goto_position, 3f* Time.deltaTime);
     
     //The problem lies here!
     transform.LookAt(Vector3.zero,world_up);
     }

Here's a picture to illustrate the problem: alt text

unity_question.png (12.9 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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Nov 15, 2014 at 03:46 AM

Well, it's pretty obvious ;) Do you see your little arrow that points up? That's what you pass as "world_up". Since that vector most likely is just Vector3.up (so in worldspace it's simply up) you get exactly what you described in your lower images.

The up vector just controls the rotation around the look vector. So you define that you want to look at "this" point and the up vector tell the function "in which direction should be up". If you want the behaviour you've described in your upper images you have to pass the "correct" up vector. However from the information provided you can't determine which is "correct".

It looks a bit like you want to have an orbit camera around that point. In this case it's way easier to place an empty gameobject at the point you want to look at, make the camera a child of it, place it locally at (0, 0, -distanceFromOjbect) by setting the localPosition of the camera to this vector and finally just rotate the empty gameobject manually.

If you use LookAt you have to provide an up vectot that represents the up you want. If you can't do that, don't use lookat ;)

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 esillen · Nov 15, 2014 at 12:31 PM 0
Share

Yes my problem is that I cannot figure out the correct expression for the up vector I want! I should have explained that this is more of a math question than a code question. I tried the second method you described as well but couldn't figure out what the rotation would be in that case either.

avatar image
1

Answer by esillen · Dec 01, 2017 at 10:31 AM

I did eventually solve this a few years ago :) My character is walking around a cube and my method was to store the difference vector between the two faces that the character was traveling between and use this as the up vector.

The big advantage of this is that the camera doesn't move so much and it looks very natural when you move around a lot on one face and then move to the next face. The camera stays put nicely on one face and can quickly move to the next without causing confusion and it was quite easy to achieve.

If you have a sphere or any other shape you can do this as well by introducing a cube. I feel there must be a better solution though but I'll just leave this here anyways.

Comment
Add comment · Show 2 · 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 Cyp26 · Dec 01, 2017 at 10:36 AM 0
Share

Thanks for this quick answer. It seems nice. I will try your solution :)

avatar image gabagpereira · Jan 22 at 04:27 PM 0
Share

I am having a really hard time to figure this out. I want to achieve the same results, but my camera keeps flipping when it reaches the center of two of the faces of the cube.

avatar image
0

Answer by Cyp26 · Dec 01, 2017 at 10:20 AM

Hello, i have exactly the same issues. Anyone who have resolved this ? Thanks

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 esillen · Dec 01, 2017 at 10:32 AM 0
Share

yeah I just put my solution here.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Flip The Entire Output in App 0 Answers

Flipping projection matrix problem: It flips everything but the Skybox. How do I fix this? 1 Answer

Camera Rotation stay behind player and not flip 2 Answers

Why does my fly though camera flip over on the first call of Input.GetAxis("Mouse X") (or Y)? 1 Answer

OnRenderImage Camera is flipped upside down 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