CharacterController isGrounded toggles value

My character controller isGrounded toggles its value even if the movement vector magnitude is zero. And when I walk it keeps toggling its value. So, if I want to jump, sometimes it doesn’t respond because it says it’s not grounded. But when you’re playing it looks completely grounded. What do you think is happening?

public float walkSpeed;
    public float rotationSpeed;
    	
    public float gravityAcceleration;
    public float verticalSpeed;
    	
    public float jumpVerticalSpeed;
    	
    private CharacterController controller;
    	
    public bool grounded;
    	
    	
    void Start () {
    	controller = GetComponent(typeof(CharacterController)) as CharacterController;
    }
    	
    	
    void Update () {
    		
    	Vector3 movement = Vector3.zero;
    		movement += transform.forward * Input.GetAxis("Vertical") * walkSpeed * Time.deltaTime;
    		
    		
    	grounded = controller.isGrounded;
    		
    	if(!controller.isGrounded){
    		verticalSpeed += gravityAcceleration * Time.deltaTime;
    		movement += transform.up * verticalSpeed * Time.deltaTime;
    	}else{
    			if(Input.GetKeyDown(KeyCode.LeftControl)){
    			Debug.Log("jump");
    			verticalSpeed = jumpVerticalSpeed;	
    		}else
    			verticalSpeed = 0;
    			
         }
    		
    		
    		transform.Rotate(0,Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime,0);
    		controller.Move(movement);
    		
    }

I have a public bool variable in order to see controller.isGrounded value in the inspector.

Actually @gnp89 and @armirblum , there is a very good reason for this,

When the charactercontroller touches a service, it shows it’s grounded. When your script notices this, it sets the vertical velocity to 0, which means, there is no change in velocity. But this also means, the player get’s pushed up a really tiny bit because of the ground and the collision and stuff. So when it moves up this tiny tiny bit, it get’s off the ground, which makes the controller think it’s not grounded anymore. When your script picks up this change, it will force it down because you implemented fake gravity. And then it happens again and again.

To fix this issue, you simply set the downwards velocity to -0.1f, or another small value, instead of 0. This means, the player will be forced down always, just by a really tiny amount. this way, the charactercontroller will always think it’s grounded, and you will always jump when needed.

@gnp89
I rarely use the isGrounded method of the character controller, since even with all the changes you can make collisions still make it buggy. Instead it the Update function, I get the position of a gameObject using gameObject.transform.position, and only jump if that position is less than any float between 0.2 to 0.5. This depends on what value you are receiving when you use transform.position. If the gameObject has already jumped, then the position will be greater than the the float, so you can use it as a condition along with Jump.triggered to make a character jump. If you want to prevent jumping when a character falls off a platform, simply do -0.5 < pos.y < 0.5.