Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Screwworkn · Jul 09, 2012 at 07:03 PM · physicsvector3

Vector3.Angle

I would have thought that the follow two debug lines would return 90 & -90 (270) but they are both returning 90. Why is this?

 Debug.Log(Vector3.Angle(new Vector3(1,0,0), new Vector3(0,1,0)));
 Debug.Log(Vector3.Angle(new Vector3(-1,0,0), new Vector3(0,1,0)));

I assume the function is working correctly, so how would I get the desire result?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by whydoidoit · Jul 09, 2012 at 07:09 PM

The angle between two vectors is always between 0 and 180 degrees. It is the angle between them and not a rotation. The angle is calculated using the dot product. See this thread for testing left and right.

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 whydoidoit · Jul 09, 2012 at 07:37 PM 0
Share

The cross product is creating a perpendicular vector - depending on whether one side is greater than the other the vector is pointing upwards or downwards. So taking the dot product of that vector against up tells you the basic orientation of the vectors. The dot product being >= 0 implies that they are pointing in the same direction and the first vector is smaller than the second.

avatar image
2

Answer by Brian Stone · Jul 09, 2012 at 07:42 PM

Mike nailed it.

If you want to know the direction that one vector is turned relative to another (i.e. clockwise or counter-clockwise) on a reference plane, then you can compare the cross product of the two vectors and compare the resulting vector's direction to the reference plane's normal vector.

Given two vectors A and B (representing rotation from vector A to vector B) and given the normal vector of a reference plane, N. Using the right-hand-rule of turning with N acting as the axis of rotation, the direction of turn is given by the following algorithm:

   // The direction of turn from vector A to vector B relative to N.
   float direction = Mathf.Sign(Vector3.Dot(Vector3.Cross(A, B), N));
   
   If direction > 0, then the turn is clockwise.
   If direction < 0, then the turn is counter-clockwise.

http://en.wikipedia.org/wiki/Right-hand_rule

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

6 People are following this question.

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

Related Questions

Rigidody.velocity = Direction * speed; How to get direction? 1 Answer

Vector3.Reflect problems 4 Answers

How do I make the bullet Tracer move towards the location of where the bullet hole prefab gets instantiated? 2 Answers

rigidbody. Velocity = Vector3.zero; ? help? 1 Answer

Raycasts in opposite directions only returning RaycastHits on right 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