I watched the video regarding dot product
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
CodePudding user response:
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.