Controller Collider is Called Constantly

I'm trying to have the ai on my characters change direction when they hit an object. Just like a goomba would 'bounce off' an object in Mario. The problem is, by using OnControllerColliderHit, it is constantly going back and forth, probably because it senses that it is colliding with the ground. How do I overcome this?

Check for or prevent collisions with the ground.

You can prevent controller collider collisions with the ground entirely by not moving down with Move or by using Move in stead of SimpleMove. Moving down with Transform.position or other methods will not trigger OnControllerColliderHit.

You can check for collisions with the ground using the ControllerColliderHit:

//by tag
function OnControllerColliderHit (hit : ControllerColliderHit) {
    if(hit.gameObject.tag != "ground") {
        //Do stuff
    }
}

or

//by position
function OnControllerColliderHit (hit : ControllerColliderHit) {
    if(hit.point.y > tooLow) {
        //Do stuff
    }
}

or

//by normal
function OnControllerColliderHit (hit : ControllerColliderHit) {
    if(Vector3.Angle(hit.gameObject.normal, transform.up) > threshold) {
        //Do stuff
    }
}

etc. There are any number of ways to check against ground collisions. The best depends on your setup.