Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 3kWikiGames · Jul 18, 2018 at 09:10 PM · cameracamera-movementstickupside-downrotaion

[PROBLEM] Camera help?

My camera tends to go upside down when viewing up or down too far, is there a way to get it to stop doing this? I'm currently using a single stick controller to control the camera. Here's my code that I hoped would constrain the camera, but it didn't work:

 if (m_Cam.transform.rotation.x < 0.4f && m_Cam.transform.rotation.x > -.4f)
                 {
                     m_Cam.transform.Rotate(-lv, 0.0f, 0.0f);
                 }
 else if (m_Cam.transform.rotation.x >= 0.4f)
                 {
                     m_Cam.transform.Rotate(-0.4f, 0.0f, 0.0f);
                 }
 else if (m_Cam.transform.rotation.x <= -0.4f)
                 {
                     m_Cam.transform.Rotate(0.4f, 0.0f, 0.0f);
                 }

Thank you so much!

Comment
Add comment · Show 3
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 Vilhien · Jul 19, 2018 at 12:04 AM 0
Share

I think there is a "simple mouse rotator" script in the third person or first person default package that might handle what you want. It can be limited to vertical only if you need, and you could limit it just right to whatever angle you need.

avatar image JVene · Jul 19, 2018 at 12:18 AM 1
Share

What you've described is called gimbal lock. The reason we use Quaternions is that they can avoid this, but when you think in terms of yaw/pitch/roll absolute angles, that returns gimbal lock to the problem. Basically, if you're looking up or down at 90 degrees, there is no difference between rolling or yawing. Rolling is how you turn a camera upside down or sideways, so the confusion of which way is up is the result.

That said, the rotation member of a transform is a Quaternion. Exa$$anonymous$$e the documentation of the Quaternion in Unity and you see they warn you not to mess with the x, y, z or w properties in the Quaternion. They should also warn you that these values don't mean what you probably assume they mean. Testing the Quaternion's x property may not do what you're expecting unless you understand Quaternions. I'm not even sure what the code would do under all expected orientations.

Starting over, basically, consider what Quaternions do for us. They are fashioned like a compass for 3 dimensions. There's a vector inside that points toward a direction, and a factor that describes the rotation in roll along that axis. This means you can apply relative rotations to the Quaternion without any gimball lock issues.

Look through and experiment with the Quaternion class provided by Unity, some attention to the "RotateTowards", the "FromToRotation" and the various examples Google provides on Quaternions (it's a study by itself).

The real point is that if we think in terms of angles by axis, we get gimball lock. When we think the way Quaternions were designed, we think in terms of relative rotations that aren't bound to the world axis, so gimball lock is eli$$anonymous$$ated.

avatar image 3kWikiGames JVene · Jul 19, 2018 at 04:10 AM 0
Share

Okay after watching a few videos and reading some on quaternions and gimbal locks I think I understand how it works, although i'm still a bit confused on how to parent one of the properties like z, so that the other properties will move along with them at the same time. I'm still a bit new to C# and would greatly appreciate any method you could lead me to that would solve this issue. Thanks for such an in depth explanation, really helped me understand it better!

0 Replies

· Add your reply
  • Sort: 

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

149 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[JS] Custom camera rotation resets on Var change? 0 Answers

How can I mimic this game's camera in Unity? 1 Answer

2D Camera Smooth follow, FixedUpdate and LateUpdate odd difference, help needed. 1 Answer

Camera smooth follow behaviour 0 Answers

Camera View Problem 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