- Home /
How to detract vector's dot product to 0?
float dot = Vector3.Dot(vec, vecNormal);
vec -= dot * vecNormal.normalized;
//Now, expecting this to be true:
//Vector3.Dot(vec, vecNormal) == 0
I'm trying to detract the vecNormal
's axis from vec
. Doing this I presume I would be able to make the dot product 0, but it doesn't work. How do I make it so? What am I missing?
Answer by Bunny83 · Aug 11, 2021 at 09:46 PM
but it doesn't work
That's not true. It does work, but it's most likely not exactly 0 due to floating point rounding errors.
Note that Unity already has a method that performs the projection you're looking for: Vector3.ProjectOnPlane. (This is literally how the method is defined).
Since you said you expect the expression to be true, I would highly recommend watching this numberphile video on floating point numbers.
Your answer
![](https://koobas.hobune.stream/wayback/20220613041532im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Uses of Vector3.Dot 0 Answers
Can't figure out why dot product isn't facing the direction I think it will 1 Answer
2 Objects Moving in the Same Direction, which is in front and behind? 1 Answer
How to visualize Vector math in Unity? 1 Answer
Change direction of vector based on which way player is facing 1 Answer