Issue with Dot Product

dot products work on vectors where each element is a scalar. It does not work on angles at all. If it’s 1, it means they are both identical. If it’s 0, they are at 90 degrees from each other. If it’s -1, they are 180 degrees away from each other.

This is why you’re using Acos.

cos of an angle of 90 degrees is 0.
cos of an angle of 0 degrees is 1.
cos of an angle of 180 degrees is -1.

Note how this is exactly similar to what you have with the dot product.

So doing Acos will find the angle between the vectors using a dot product for this reason.

Note that your DotProd variable is not the dot product, it is the angle of the dot product. It is in radians.

The value you’re displaying is an angle multiplied by the Z of the cross product. I have no idea what you’re trying to do here. Could you explain what you’re trying to do? My guess right now is that FMath::Acos is not needed.

What you have right now is a vector from AI forward. And a vector from AI to the player. You take a cross product meaning the vector will point straight up. You then scale the Z axis of this straight up vector by the dot product. Assuming you’re not using Acos, it would be zero when the AI is facing the player.

Later you say you need the negative rotation to determine the direction for certain animations. If you want the angle, just use UKismetMathLibrary::FindLookAtRotation(AILocation, PlayerLocation).Yaw and subtract AI->GetActorRotation().Yaw

No need for dot products or any of that.

1 Like