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
2
Question by uberalles · Sep 29, 2015 at 06:56 PM · rotationangles

Quaternion.Angle always returns zero

I have object that runs towards a set destination (set through right-click) and the object arrives perfectly but I also have a desired rotation being stored when the user holds down the right mouse button and picks a rotation (a graphical arrow appears to show rotation). Everything works until the object reaches its destination when I want the object to rotate to face the desired rotation. I have a check method to see if the rotation difference between the object and desired but it always returns zero, even if I manually rotate the object (just around the y-axis), no matter what it always comes back as a zero difference.

 bool CheckAngleDifference(Quaternion a1, Quaternion a2,float diffAmnt)
     {
         print (a1 + " - " + a2);
         print ("angle diff: " +Quaternion.Angle (a1, a2));
         if (Mathf.Abs (Quaternion.Angle (a1, a2)) > diffAmnt)
             return true;
 
         return false;
     }

I have made this work using: Quaternion.Angle (transform.rotation, (Quaternion.LookRotation (newDest - transform.position, Vector3.up))) but in this case the positions are the same since it has arrived at its destination. Any idea why Quaternion.Angle keeps coming back as zero and how can I get the object to face the desired rotation after arriving at its destination. Big thanks in advance for any hep.

Comment
Add comment · Show 9
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 meat5000 ♦ · Sep 30, 2015 at 10:50 AM 0
Share

it always comes back as a zero difference

Is this according to your print statement?

avatar image uberalles · Sep 30, 2015 at 12:43 PM 0
Share

An if statement as well.

avatar image meat5000 ♦ · Sep 30, 2015 at 12:57 PM 0
Share

You cant debug Quaternion.Angle (a1, a2)

via the if statement as it adds in other factors. Your print throws out 0 every time?

How about if you use

 float diffAngle = Quaternion.Angle (a1, a2);
 print (diffAngle.ToString());
avatar image uberalles meat5000 ♦ · Sep 30, 2015 at 01:02 PM 0
Share

I still get zero every time, no matter the angles.

avatar image meat5000 ♦ · Sep 30, 2015 at 01:29 PM 0
Share

So what does the print for a1 and a2 say?

Your code works for me.

All I can suggest is that you are incorrectly setting up your quaternions.

Are you sure you aren't requiring Vector3.Angle ins$$anonymous$$d?

avatar image uberalles meat5000 ♦ · Sep 30, 2015 at 02:03 PM 0
Share

When the object (character) arrives at its destination I get a1 = (0.0,-1.0,0.0,-.02) and a2 = (0.0,-174.1,0.0,0.0) and the whole time angle difference is zero. So you when run that you get a result other than zero? Very strange (thanks for the responses btw).

avatar image meat5000 ♦ · Sep 30, 2015 at 02:08 PM 0
Share

Here, I placed this code on an empty object then created 2 cubes, which I dragged into the transform entries of the script. Rotating the cubes then pressing G prints the result.

 using UnityEngine;
 using System.Collections;
 
 public class AngleTest : $$anonymous$$onoBehaviour {
 
     Quaternion q1 = Quaternion.identity;
     Quaternion q2 = Quaternion.identity;
     float diff = 0;
 
     public Transform t1;
     public Transform t2;
     
     void Update () {
 
         q1 = t1.rotation;
         q2 = t2.rotation;
 
         if(Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.G))
         {
             CheckAngleDifference(q1,q2,diff);
         }
     }
 
     bool CheckAngleDifference(Quaternion a1, Quaternion a2, float diffAmnt)
     {
         print (a1 + " - " + a2);
         print ("angle diff: " +Quaternion.Angle (a1, a2));
         if ($$anonymous$$athf.Abs (Quaternion.Angle (a1, a2)) > diffAmnt)
             return true;
         
         return false;
     }
 }
avatar image uberalles meat5000 ♦ · Sep 30, 2015 at 02:14 PM 0
Share

Yea, I get a non-zero result as well. Obviously the problem is somewhere else. When I get this figured out I'll post the results. Thanks again!

avatar image meat5000 ♦ uberalles · Sep 30, 2015 at 02:16 PM 0
Share

Glad I could help.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by disorganized · Jan 14 at 07:36 PM

dude...that was posted over 6 years ago.

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

Answer by Amir1360 · Jan 14 at 02:42 PM

Please refer to this:

A more accurate function to calculate the angle between two rotations

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.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue finding an angle with trigonometry 1 Answer

Clamp Rotation of an object depending of the Rotation of an other one 0 Answers

How to check object "rotated" X degrees 1 Answer

Setting rotation Angle / rotation question 1 Answer

I want to rotate object away or towards camera around x-axis 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