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 Jack 4 · Nov 11, 2010 at 04:50 PM · rotationphysicsmathangle

physics & rotation question

how two perpendicular vectors can have a dot product not equal to 0 in Unity?

Thats my script for a simple Cube, that moves only in 2D:

void OnCollisionEnter(Collision collision) { ContactPoint contact = collision.contacts[0];

     //Calculate reflection Vector3 on collision normal
     reflect_direction = Vector3.Reflect(rigidbody.velocity.normalized, contact.normal);
     impact_direction = rigidbody.velocity.normalized;
     angle = Vector3.Dot(reflect_direction, impact_direction);        

}

Now for example In my on screen display I see values as:

angle == 0,9852035

impact_direction == 0.1, 1.0, 0.0

reflect_direction == -0.1, 1.0, 0.0

How on earth is the dot product close to 1 !?!?!?!

Also what worries me is the fact, that for this example, the ship was flaying with big velocity in the OX axis and the impact_direction shows, that the OY value is bigger ?!?

Any help?

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 VS48 · Nov 11, 2010 at 05:13 PM

Well, those vectors are not perpendicular, they are reflected along the X axis.

And their dot product is:

(-0.1*0.1)+(1.0*1.0)+(0.0*0.0) = (-0.01)+(1.0) = 0.99

So to get the angle, you'd have to divide the dot product by the product of the magnitudes of the two vectors. Ex:

angle /= (Vector3.Magnitude(reflect_direction) * Vector3.Magnitude(impact_direction));

Edit: Woops, don't forget to take arc-cosine of the above result to get the angle!

Or, you can just use the Vector3::Angle function:

angle = Vector3.Angle(reflect_direction, impact_direction);
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 Jack 4 · Nov 11, 2010 at 07:23 PM 0
Share

So stupid of me! Ofcourse they're not perpendicular. What was I thinking :/ Thanks a lot!

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

No one has followed this question yet.

Related Questions

Trying to rotate my catapult's launch arm. 1 Answer

Problem with Clamping Values for Object's Rotation 1 Answer

How to make any dice have a given face(int) face up? 1 Answer

Calc 30° left and x units forward from local forward axis 1 Answer

How to calculate the angle of a trajectory to hit the target 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