It depends on exactly what you mean by "A is facing B", but you can use the same approach mentioned in the link you give. The other vector to examine (in addition to the direction
A is facing) is the one connecting and pointing from
B (calculated by
Your code would be something like.
facing = dotProduct(normalize(B-A), normalize(directionFacingOfA))
Which will give you the cosine of the angle between where
A is facing, and the vector where
B. Pretty easy. Three possibilities:
B almost perfectly (angle close to 0),
facing will be close to 1 (
A isn't facing away from
facing will be between 0 and 1. It is up to you to decide if this is "close enough".
A is facing away from
facing will be negative.
This approach works for either 2D or 3D.