title: Unity3d OnTriggerEnter collision direction detection
body: <p>Okay, so I believe this concept should be simple.  However, the answer is eluding me.  Editor background.  The "other" object and the gameObject with this code both have sphere colliders which are as triggers, this gameObject has a CharacterController attached for movement, but neither have RigidBodies.  My goal is for this (the Player object, moving around automatically PacMan style) to kill things it runs in to, but only if it is facing them, otherwise, it should take damage.  My issue is figuring out how to tell if it was facing the object. To complete the picture, moveDirection can be one of the following (Vector3.Up, .Down, .Left or .Right) as the Player and NPC's move along the X and Y axes only (Orthographic Camera with 3D game objects)</p>
  
  <p>~ OLD METHOD</p>
  
  <pre><code>    void OnTriggerEnter (Collider other)
      {
  
          if (other.gameObject.tag == "Human") {
              RaycastHit hit;
              if (Physics.Raycast (transform.position, moveDirection, out hit)) {
                  StartCoroutine (eatWithBlood (1, other.gameObject.GetComponent&lt;NPCController&gt; ()));
              } else {
                  TakeDamage (other.gameObject.GetComponent&lt;NPCController&gt; ().attack);
              }
  
          } 
      }
  </code></pre>
  
  <p>I've also tried the following code, which works a little better.  The math doesn't work quite right, so even if the angles are between 45 and -45, the player still gets "stunned" and takes damage.  The new method is preconfigured to expand should I need the other variables for more accurate calculations.  the faceDirection variables are up=0, right=1, down=2, left=3 which also correspond to their Vector3.up, left, down and right cohorts.</p>
  
  <p>~ NEW METHOD</p>
  
  <pre><code>void OnTriggerEnter (Collider other)
      {
  
          if (other.gameObject.tag == "Human") {
              float angle = Vector3.Angle (transform.forward, other.gameObject.transform.position);
              Debug.Log ("Angle: " + angle + "; my forward: " + faceDirection + "; other forward: " + other.gameObject.GetComponent&lt;NPCController&gt; ().faceDirection + " ... " + Time.time);
              if (IAteHim (faceDirection, other.gameObject.GetComponent&lt;NPCController&gt; ().faceDirection, angle)) {
                  other.gameObject.GetComponent&lt;NPCController&gt; ().EatMe ();
                  StartCoroutine (eatWithBlood (1, other.gameObject.GetComponent&lt;NPCController&gt; ()));
              } else {
                  GameObject poof = PoofPooler.poof.GetPooledObject ();
                  if (poof != null) {
                      poof.transform.position = Vector3.Lerp (transform.position, other.gameObject.transform.position, 0.5f);
                      poof.GetComponent&lt;PoofControl&gt; ().reactivated = true;
                      poof.SetActive (true);
  
                  }
                  other.gameObject.GetComponent&lt;NPCController&gt; ().MakeInvincible ();
                  TakeDamage (other.gameObject.GetComponent&lt;NPCController&gt; ().attack, 2.0f);
              }
  
  
          }
      }
  
      bool IAteHim (int myDirection, int otherDirection, float angle)
      {
          if (angle &gt; -45 &amp;&amp; angle &lt; 45) { // I'm facing toward yummies
              return true;
          } else {
              return false;
          }
  
      }
  </code></pre>