How to detect if ObjectA is looking at ObjectB, and vice versa?

Hi, I’m trying to make a Super Mario World Boo type enemy, but I am having some difficulties trying to get it working.
From what I’ve seen, a lot of people recommend using a Dot Product, and this is the current version of that script I have.

    Vector3 Dis = (player.transform.position - transform.position).normalized;
    float d = Vector3.Dot (Dis, transform.position);
    Debug.Log(d);

However, the dot product returns with values greater than 1 or lower than -1, which I don’t think is correct. The code above is in the enemy script.
Any help is greatly appreciated!

hello @Nekobolo! I think you can use raycast or line cast to detect objective A is looking at object B.

check this for Ray Cast:https:

and for line cast check this:

hopefully it can help.

I ended up solving this by calculating the X coordinate difference between the enemy and player, and then seeing if the player was facing left or right.

Example:

		if (XDif > 0 && player.facingRight == true)
		{
			Debug.Log("CAN'T MOVE");
			speed = 0f;
			facingPlayer = true;
		}