I watched the video regarding dot product https://www.youtube.com/watch?v=xlnkTEyAx7Q and try to sum up the result with the formula a.b = |a||b|Cosθ but I couldn’t get it. Please help to point out where the mistake. Consider two object a, at position (ax,0,az) and b, at position (bx,0,bz), from the built in function in the video, vector3.Normalize(b.position-a.position) would return the value of the unit vector/direction of b toward a.
since both lies at y=0, it as if 2 object lies at 2D plant x and z
so vector3.Normalize(b.position-a.position) should produce
and consider object a facing(ax,0,az) direction then a.forward will produce
Lastly, vector3.Dot(a.forward,vector3.Normalize(b.position-a.position)) should produce
Try to compare the result in google a.b = |a||b|Cosθ
Both result entirely different. Please help me to understand these formula and correct my mistake
>Solution :
The angle θ is the angle between the vectors a and b. This is important. And cos(θ) is the value which is shown in the video. But in your equations, you are finding the vector (b – a) and finding the angle between this and a. So your vector3.Dot(a.forward,vector3.Normalize(b.position-a.position)) does not equal cos(θ) but cos(the angle between a and b-a). And this is not what you want.
You should rather do vector3.Dot(vector3.Normalize(a),vector3.Normalize(b)) since this is the same as
(a/|a|).(b/|b|) = (a.b) / (|a| * |b|).
Your last formula is correct.


