How to tell if a transform is facing another in Unity3d

Jun 11, 2013 • val antonini

A helpful method to check to see if a transform is facing another transform in Unity3d

private bool IsFacing(Transform target)
{
    Vector3 forward = transform.TransformDirection(Vector3.forward);
    Vector3 toTarget = target.position - transform.position;
    return Vector3.Dot(forward, toTarget) > 0;
}