• 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 /
  • Help Room /
avatar image
0
Question by rwrd · Dec 30, 2016 at 02:41 PM · rotationtransformarraypositionquaternion

Quaternion.RotateTowards for camera positions is buggy

I am trying to have set camera positions that the user can scroll between using two keys. I can switch the positions fine but rotating doesn't work. I have the position correct but not this.

     private Quaternion[] Rotations;
     private Vector3[]    Positions;

Starting with two arrays. Obviously the rotations are Quaternion so that is what I am using for this scenario. I have only 5 positions to switch between so:

     Rotations = new Quaternion[5];
     Positions = new Vector3[5];

I initialize our array and set the initial positions.

     Rotations [0] = transform.rotation;
     Positions [0] = transform.position;

As an example here are our first two different positions. All the rest are extremely similar and inputting these values manually into the transform component seems to work fine.

 Positions [1] = new Vector3 (11.67f, 4.52f, -5f);
 Rotations [1] = new Quaternion (25, -90, 0, 0);


Then when they are switched we check if our position is not correct according the value inside the array on the current position index. If it is not then rotate and move towards these positions:

         if (transform.position != Positions [CurrentCamIndex]) {
             transform.position = Vector3.MoveTowards (transform.position, Positions [CurrentCamIndex], 1);    
             transform.rotation = Quaternion.RotateTowards (transform.rotation, Rotations [CurrentCamIndex], 1);
         }

But as soon as I run this I get some weird rotations:

alt text

As you can clearly see the transform component in the inspector contains some values I don't even have here. Is there anything I am missing or anything I am doing incorrectly?

rotate.png (239.4 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

Answer by Owen-Reynolds · Dec 30, 2016 at 04:08 PM

Don't use new Quaternion(. It gives junk results. Use Quaternion.Euler( instead.

Inside, quaternions use complex non-degree math. new Quaternion and rotation.x are there for the few people who understand it. For everyone else, Quaternion.Euler and rotation.eulerAngles.x translate it into degrees for us (My longer explanation is at taxesforcatses-dot-com in the move/rotate section (the first section about rotations, near the bottom.)

Comment
Add comment · 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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

transform rotation inaccuracy 0 Answers

Car weirdly flips 180 degrees while rotating to ground normal 0 Answers

Array transform.position from another script 1 Answer

How can i use transform.position to a gameobject in an array? 1 Answer

Weird rotation when using Slerp!!? 3 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