Hit detection at angles of enemy character controller?

I'm trying to get some raycast and/or collision detection working.

If my enemy gets hit by a car on his left side, an animation will play of him tumbling away to the right. I'm not using physics for the collision, the animation for each direction is already finished.

I'm hoping to develope this enemy script to detect both raycast hits (machine gun) and collider hits (rocket, car, etc) and will share the end results.

The script needs to to figure the angle of hit on the controller and fire the script. I'm thinking something along lines of:

if(hit.angle>180) animation.Play("tumbleLeft");

if(hit.angle<180)
animation.Play(“tumbleRight”);

Seems the class "ControllerColliderHit" would get me started but still having trouble getting it together.

Any info is greatly appreciated.

You could use a Dot product of the hit direction and the left or right facing of the player. The dot product is > 0 if they're +/-90 degrees.

void OnCollisionEnter( Collision collisionInfo )
{
  Vector3 hitDir = collisionInfo.contacts[0].point - transform.position;
  Vector3 left = transform.TransformDirection( Vector3.left );
  if( Vector3.Dot( left, hitDir ) > 0 )
  {
    Debug.Log("Hit from Left");
  }
  else
  {
    Debug.Log("Hit from right");
  }
}

Edit: an attempt at a JS version:

function OnCollisionEnter( collisionInfo : Collision ) 
{
  var hitDir : Vector3 = collisionInfo.contacts[0].point - transform.position;
  var left : Vector3 = transform.TransformDirection( Vector3.left );
  if( Vector3.Dot( left, hitDir ) > 0 )
  {
    Debug.Log("Hit from Left");
  }
  else
  {
    Debug.Log("Hit from right");
  }
}

The OnCollisionEnter event in the docs is here.