Character Controller .isGrounded=false while moving left or right

I am making a 2D game. I have a character controller with gravity. When the controller is grounded isGrounded=true. But when the character is grounded and the character is moving left or right isGrounded=false.

using UnityEngine;
using System.Collections;

public class PlayerC: MonoBehaviour {
	
	
private CharacterController controller;
	
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController>();
}
	
// Update is called once per frame
void Update () {
		

//left / right
if(Input.GetAxis("Horizontal") > 0)
{

	controller.Move(Vector3.right * Input.GetAxis("Horizontal") * Time.deltaTime);
		}
		else if(Input.GetAxis("Horizontal") < 0)
		{

			controller.Move(Vector3.right * Input.GetAxis("Horizontal") * Time.deltaTime);
		}

		print (controller.isGrounded);
		
		//jump
		if(Input.GetButton("Jump") && controller.isGrounded)
		{
			controller.Move (Vector3.up * 10 * Time.deltaTime);
		}
		
		//gravity
		controller.Move (Vector3.down*2 * Time.deltaTime);
		
	}
	
}

I can not figure out why isGrounded is becoming false when I am using controller.Move. It is a very annoying problem.

The reason why your isGrounded is always false, is because you are checking it before you apply gravity, it is therefore not grounded at that point. Then you apply gravity and it becomes grounded.

Whenever using the character controller, you should also never call .Move more than once per frame. Mostly because it causes these problems, but also for optimisation purposes.

I’m glad it helped :slight_smile:
Benproductions1