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 goharjaved · Aug 16, 2014 at 07:23 PM · physicsmath

Dot Product of Vector

I am new in unity development.And i have searched many forums for Vector Dot product. I could not understand what is the basic purpose of dot product ,Is it for direction matching of two game objects thanks for help in Advance it shall be highly appreciated

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
2

Answer by robertbu · Aug 16, 2014 at 07:32 PM

The dot product is the magnitude of the projection of one vector on another. It is a basic vector concept that is used in a variety of places, like projecting a point on a plane, or figuring out what side of a plane a point is on. In Unity Answers we primarily see it used to detect direction.

Given two normalized vectors, the closer they are aligned, the closer the Dot product will be to 1.0. If they were at right angles to each other, then the value would be 0.0. A value of -1.0 indicates the vectors are opposite of each other. Note that it is not a linear progression. That is a value of 0.5 is not mean the two vectors are 45 degrees away from each other. If you need a linear progression, use Vector3.Angle().

For example, say you had a pair of dice and you want to check each one for which side was up. You could use Vector3.Dot() with each of the transform sides (transform.forward, transform.right, transform.up) against Vector3.up. A value near 1.0 would indicate that side was up. A value near -1.0 would indicate the opposite side was up. If none of the values were near 1.0, you would know the die was not resting flat on a surface.

Comment
Add comment · Show 4 · 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 goharjaved · Aug 16, 2014 at 07:46 PM 0
Share

Thanks For Reply How can i use it for Car parking? Actually i am working on car parking game in which i want parking when car and parking are in same direction . I used Position for it but it is not working in my case.

avatar image goharjaved · Aug 16, 2014 at 07:53 PM 0
Share

here is my Code snippet void Update () { Vector3 current = transform.TransformDirection (Vector3.down); if(Physics.Raycast(transform.position , current ,out hit , 30)) { if(hit.collider.gameObject.name == "Parking") { if (Vector3.Dot(transform.position , hit.collider.transform.position) > 0) { Debug.Log("samse direction"+Vector3.Dot(transform.localPosition.normalized , target.transform.position)); }

         }
     }

 }
avatar image robertbu · Aug 16, 2014 at 07:59 PM 0
Share

Two issues. First, you need to use a direction, not a position. So it would be something like:

  Vector3.Dot(transform.forward, hit.transform.forward) 

So this compares the forward of both vehicles. Next, I'm not sure what you want for a value. Using 0.0, means they are anywhere withing 90 degrees of each other. I don't know your game, but I would think you would want a higher value:

 if (Vector3.Dot(transform.forward , hit.transform.forward) > 0.8f) {

P.S. For future posts of code, please select your code after pasting and use the 101/010 button to format it.

avatar image goharjaved · Aug 17, 2014 at 06:46 AM 0
Share

Thanx alot Next time i will post code in the code section thanx alot

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

2 People are following this question.

avatar image avatar image

Related Questions

How to calculate desire angular velocity? 1 Answer

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

Calculate Initial Velocity to Reach Destination Based Off Time 1 Answer

My character moves in seemingly random directions. 1 Answer

Reflection Angle - Change objects rotation 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