bizarre collision modulations with character controller

Strange predicament here, I have my character, and he’s using: a character controller, the third person controller that comes in the character controller’s package, and two other scripts, ‘animate’ which controls animation, and ‘attack’ which is the script giving me all this trouble. So here’s what i want to do: make my character, when a button is hit, shoot down rapidly, and when he hits the ground or an enemy, attack it. I’m starting by just printing things instead of actually attacking. Here’s the script:

var attackButton = "Fire1";
function Update () {
	var controller : CharacterController = GetComponent(CharacterController);
	var variables = GetComponent("ThirdPersonController");
    if (controller.isGrounded){
    	if (Input.GetButton(attackButton) && variables.gravity == 500){
    	variables.gravity = 40;	
    if (!controller.isGrounded){
    	if (Input.GetButton(attackButton)){
    	variables.gravity = 500;
    	variables.gravity = 40;

Here’s the problem, he shoots downward fine, and stops when he hits ground, however, when i’m just sitting still and looking at the debug strip at the bottom of the screen it modulates : “OnGround”, “InAir”, “OnGround”, “InAir”, “OnGround”, “InAir”.
What this does is make it so the player can ‘attack’ the object beneath him while sitting still. I see this as a bizarre error. Do you guys have any suggestions as to fixing this? is there something wrong with the script? is this a Unity error? Any help is greatly appreciated! Thank you!

-Stopsecret Design

This problem is described here. You can solve it by applying gravity every frame, even when you’re ‘Grounded’.

(In our code we have something like this… it keeps the character at ‘near 0’ velocity when they’re on the floor and stops them flickering into the air tiny amounts)

    velocity.y = 0; //assuming gravity is in y
 velocity += Physics.gravity * Time.deltaTime;