• 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 Brandon 2 · Sep 29, 2010 at 04:59 AM · physics

Vector3.RotateToward - Camera flips when revolved about origin through y = 0.

Setup: I have a simple point-click application that displays a collection of spheres in a dodecahedron shape. You can click on any sphere to bring that sphere into focus (the camera rotates about the origin toward the new point of focus).

Observe: [http://theclassicgaming.appspot.com/][1]

Note: Notice that some vertical rotations fail. In fact, there are two pair that fail and two pair that succeed. I have only a limited understanding of linear algebra, but as near as I can figure, the failure occurs when it rotates through y=0 about the z-axis. I'm sure an undefined slope has something to do with it.

Question: Have I a flaw in my math? Need I write some work-around for the particular case that fails? As of yet, I am at a loss for work-around words.

Code:

// called when a node is clicked private void FollowNode(WorldNode node) { if (node == null) _currentTarget = Vector3.zero; else _currentTarget = node.Position.normalized * cameraDistance; }

// called in update private void AnimateCamera() { if (transform.position != _currentTarget) { Vector3 newPosition; Quaternion newRotation = Quaternion.identity; float rs = Time.deltaTime * rotateSpeed; newPosition = Vector3.RotateTowards(transform.position, _currentTarget, rs, 0.000125f); newRotation.SetLookRotation(-newPosition, Vector3.up);

     transform.position = newPosition;
     transform.rotation = newRotation;
 }

}

Remark: I was planning on displaying the camera position and rotation with GUI text, but I have yet to work that part out. As I look at this more, I wonder if the problem actually lay in my use of SetLookRotation.

PS: This is what part of the alphabet would look like if Q and R were eliminated.

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 Bampf · Sep 29, 2010 at 09:29 PM

This is only a guess, but I wonder how it would look if you color-coded the nodes, or had a skycube, or objects in the background. Specifically, I'm thinking the "failed" rotations are actually succeeding, but the math reaches a point where the view rotates instantly upside-down. The symmetry in the model would make it impossible to tell.

If I'm right, note that the SetLookRotation has no limits on how fast it rotates. You could use Slerp to limit how fast the view spins. That's just one possible fix. Or maybe there's a safer way to change the look rotation that avoids the inversion.

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 Brandon 2 · Sep 30, 2010 at 02:59 AM 0
Share

Yes, it's all so obvious now. As soon as I read your comment, I realized that the camera is, indeed, flipping over. As the camera rotates around the graph, it reaches a point where it must necessarily be upside down. However, since I've constrained its up to Vector3.up, it then flips over. Come to think of it, rotating the graph is a better solution anyway, since moving the camera limits what other objects can be in scene.

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

When dragging a Door open using RIGIDBODYSCRIPT Plays sound. 1 Answer

Determine Area using code 1 Answer

How to keep physics consistent? 1 Answer

constant force 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