Dot product not working when Enemy change its direction
HI ,Recently I am learning dot product,
While below code works from Unity's documentation, http://docs.unity3d.com/ScriptReference/Vector3.Dot.html
public Transform other;
void Update() {
if (other) {
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 toOther = other.position - transform.position;
var dot = (Vector3.Dot(forward, toOther);
Debug.Log(dot);
}
}
But it doesn't work when I change direction of "other".It keeps giving same value no matter how much I rotate other unlike when I rotate transform,it does change values.
For example, transform is at 0 0 0 and other is at 0 0 10 both has 0 rotation so facing straight in Z axis.
The desiire out put I get is negative.
Now suppose I change rotation of transform to 180 then the output gets positive as expected.
I undo the rotation of trasnform and rotate other to 180 i.e., facing transform, then the output doesn't get change and show negative value only.Which is not correct as other is facing player..
Why is that the case? I am not able to get around it.