disable movement help

Hey Guys, I’m a noob at this and I’m trying to disable player movement when there is nothing overlapping with the box component that I attached to my main character.




AfpsCharacter::AfpsCharacter()
{
    // Set size for collision capsule
    GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);

    // set our turn rates for input
    BaseTurnRate = 45.f;
    BaseLookUpRate = 45.f;
    bIsCollided;
CollisionMesh = CreateDefaultSubobject<UBoxComponent>(FName("Collision Mesh"));
    CollisionMesh->SetupAttachment(GetRootComponent());


    // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 
    // are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)
}

void AfpsCharacter::BeginPlay()
{

    Super::BeginPlay();

    CollisionMesh->OnComponentBeginOverlap.AddDynamic(this, &AfpsCharacter::OnOverlapBegin);
    CollisionMesh->OnComponentEndOverlap.AddDynamic(this, &AfpsCharacter::OnOverlapEnd);

}

void AfpsCharacter::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
    bIsCollided = true;
    UE_LOG(LogTemp, Warning, TEXT("colliding"));
}

void AfpsCharacter::OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
    bIsCollided = false;
    UE_LOG(LogTemp, Warning, TEXT("not colliding"));
}



void AfpsCharacter::MoveForward(float Value)
{
    if ((Controller != NULL) && (Value != 0.0f))
    {
        // find out which way is forward
        const FRotator Rotation = Controller->GetControlRotation();
        const FRotator YawRotation(0, Rotation.Yaw, 0);

        // get forward vector
        const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
        if (!bIsCollided)
        {
            AddMovementInput(Direction, Value);
        }
    }

}

void AfpsCharacter::MoveRight(float Value)
{

        if ((Controller != NULL) && (Value != 0.0f))
        {
            // find out which way is right
            const FRotator Rotation = Controller->GetControlRotation();
            const FRotator YawRotation(0, Rotation.Yaw, 0);

            // get right vector 
            const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
            // add movement in that direction
            if (!bIsCollided)
            {
                AddMovementInput(Direction, Value);
            }
        }


}