isGrounded not working

This seems to be a basic problem but I just can not figure this out of the life of me. The code is simple:

if (controller.isGrounded) {
	verticalspeed=-gravity * Time.deltaTime;
	print("Grounded.");
}
else {
	verticalspeed-=gravity*Time.deltaTime;
	print("Ungrounded");
}
controller.Move(transform.TransformDirection(0,verticalspeed,0) * Time.deltaTime);

However, even when the controller is hitting the ground, the “Grounded” state is never triggered. Thus, the vertical speed continues to increase, causing basically infinite speed when falling after a few seconds in-game. Any help would be extraordinarily appreciated, considering this has had me stuck and stumped for several weeks.

I’ve found a solution to this problem after a bit of plagiarism. I went in to the standard 3rd person controller and noticed that they did all of their motion in one single move function per frame - I adopted this (basically by lifting it straight out of their code in to mine) and it seems to work better. I’m still not sure why my initial code did not work (perhaps running two move commands per frame causes issues?) but this seems to work much better. For anyone who’s interested:

var targetDirection = Input.GetAxis("Vertical") * transform.forward + Input.GetAxis("Horizontal") * transform.right;
var movement = targetDirection * speed * Vector3(0, verticalspeed, 0);
movement *= Time.deltaTime;
controller.Move(movement);

try this:

if (controller.isGrounded)
{
	verticalspeed += gravity * Time.deltaTime;
	print("Grounded.");
}
else
{
	verticalspeed -= gravity * Time.deltaTime;
	print("Ungrounded");
}
controller.Move(transform.TransformDirection(0, verticalspeed, 0) * Time.deltaTime);

I solved that by just increasing the gravity var enought, of course that will cause jumping problems, but when you jump, you just decrease the gravity var to get soft jump, then, when the isGrounded turns true again, increase again the gravity…