• 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 Leight · Oct 08, 2016 at 02:50 PM · scripting problembug-perhapsunity 5.2

[BUG?] Vector3.Dot() product returns -1.47

Hello. Just faced some strange behaviour of Vector3.Dot().

It can be reproduced by this code:

         Vector3 v3cTest = Vector3.forward;
 
         v3cTest = Quaternion.AngleAxis(45f, Vector3.up) * v3cTest;
         v3cTest = Quaternion.AngleAxis(45f, Vector3.up) * v3cTest;
 
         float testDot = Vector3.Dot(v3cTest, Vector3.forward);

Just run debugger and watch v3cTest value. It will be like this: testDot = Vector3.Dot( (1.0, 0.0, 0.0), (0.0, 0.0, 1.0)); So you 'll expect 0 but result will be -1.47.

Maybe i'm doing somthing wrong?

Comment
Add comment · Show 5
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 Owen-Reynolds · Oct 08, 2016 at 03:28 PM 0
Share

Yes, you are doing something wrong. Read your answer again. It's not -.147. It's really 0 with a rounding error.

$$anonymous$$ost people renormalize after doing math, if it really, really matters (which it almost never does.)

avatar image Leight Owen-Reynolds · Oct 09, 2016 at 11:26 AM 0
Share

screenshot

Sorry, i still don't understand. Are you sure that its a roundng error?

I mean, function returns really weird result without warning and stuff... so any logic that comes after will be broken.

I solved this problem via replacing vector rotations with more simple math but still .

testdot.png (13.6 kB)
avatar image doublemax Leight · Oct 09, 2016 at 11:37 AM 0
Share

I'm not sure what you're doing, but the following code always outputs "0" for me:

   float test = Vector3.Dot( new Vector3(1.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f));
   Debug.Log("Test = " + test);
Show more comments
avatar image doublemax Leight · Oct 09, 2016 at 11:46 AM 1
Share

I didn't see the screenshot before.

-1.47513973E-07f is -0.000000147513973

I'd say that's close enough to 0.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Leight · Oct 09, 2016 at 11:55 AM

@doublemax Okay its just -1.47 * 1/(10^7)? And its was near but not 0 because of double rotation. Got it, Thanks for explanation!

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't add script to anything. 1 Answer

Material and RenderTexture produce unexpected results when disabled/released. 0 Answers

How to switch between two lightmaps in unity 5 1 Answer

Debug.Log not working 1 Answer

Why is the color of the player not changing properly? 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