C++ Reset bMoving value, after no more input from keyboard

I am trying to have a bMoving variable, to see if the MC is still moving or not. If MC is moving, it has certain abilities (e.g. Sprint). If MC is Idle, cannot Sprint.

I have been racking my brains for 2 days, and cannot seem to figure this out. I am fairly new to C++ and game programming.
With the code below, after the first input from keyboard, if I try to Sprint in Idle, the MC will start sprinting in place.

void AMain::HandleGroundMovementInput(const FInputActionValue& Value)
{
//default movement code (move function when project is created)
if (!CustomMovementComponent) return;

if (CustomMovementComponent->IsClimbing())
{
    HandleClimbMovementInput(Value);
    
}
else
{
    bMoving = false;
    
    if (CanMove(Value))
    {
        // input is a Vector2D
        const FVector2D MovementVector = Value.Get<FVector2D>();
        
        // find out which way is forward
        const FRotator Rotation = Controller->GetControlRotation();
        const FRotator YawRotation(0, Rotation.Yaw, 0);

        // get forward vector
        const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);

        // get right vector 
        const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

        // add movement 
        AddMovementInput(ForwardDirection, MovementVector.Y);
        AddMovementInput(RightDirection, MovementVector.X);
                    
        bMoving = true;
    }
}
}

bool AMain::CanMove(const FInputActionValue& Value)
{
const FVector2D MovementVector = Value.Get<FVector2D>();
if (MainPlayerController)
{
    return (Controller != nullptr) && 
        (!MovementVector.IsZero()) && (!bAttacking) &&
        (MovementStatus != EMovementStatus::EMS_Dead) && 
        (!MainPlayerController->bPauseMenuVisible);
}
return false;
}

Thank you for your consideration.

Leave a Comment