Character stuttering down slopes

Because of a relatively low gravity on my character controller, the character walking/running animation stutters when moving down slopes. (Every few milliseconds it recognizes him as being in mid-air, so it keeps switching between animations). I can increase the grounded gravity to fix this but then when the player walks off a ledge they fall like a dead weight compared to when they fall from a jump. Any ideas how I could try overcoming this issue?

function ApplyGravity () {
	if (controller.isGrounded) {
		// Keep reset when on ground
		movement.verticalSpeed = -movement.gravity;
		movement.airTime = 0.0;
		movement.leaping = false;
		activeInput.move = true;
	}
	else {
		// Start counting time in air
		movement.airTime += Time.deltaTime;
				
		// When we reach the apex of the jump, set reachedApex to true
		jump.reachedApex = jump.jumping && !jump.reachedApex && movement.verticalSpeed <= 0.0;
	
		// When jumping up we don't apply gravity for some time when the user is holding the jump button for a higher jump
		var extraPowerJump = jump.jumping && movement.verticalSpeed > 0.0 && jump.jumpButton && transform.position.y
			< jump.lastStartHeight + jump.extraHeight && !IsTouchingCeiling ();
		
		// Apply gravity to vertical speed
		if (!extraPowerJump)
			movement.verticalSpeed -= movement.gravity * Time.deltaTime;
	
		// Make sure we don't fall any faster than the terminal velocity
		movement.fallSpeed = -movement.terminalVelocity;
		
		// Check for wallsliding (and if so, decrease fallSpeed)
		WallSliding ();
		
		// Check vertical speed against terminal velocity
		movement.verticalSpeed = Mathf.Max(movement.verticalSpeed, movement.fallSpeed);
	}
}

I see two ways :

  • Add a delay between the calculation of is grounded and it’s affectation like once isGrounded is supposed to be turned off, start a coroutine which turned isGrounded to off after 0.5 only if it wasn’t grounded back inbetween.
  • Cast a ray downward, if it’s far enough you can consider yourself not grounded. You might force it for a jump though.