> For the complete documentation index, see [llms.txt](https://lifeexe-art.gitbook.io/unreal-engine-c-course-eng/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lifeexe-art.gitbook.io/unreal-engine-c-course-eng/lessons/lecture-065/blocking-shooting-while-running.md).

# Blocking shooting while running

The ability to shoot while running looks unrealistic due to our running animation, so it's best to disable shooting while running.

I highly recommend that you first try to implement this logic by yourself, as a homework task.

Improvement can be done after **Lecture 065** or at the very end of the course.

### Solution

* Add a new flag to the base weapon class `FireInProgress`

```cpp
void ASTUBaseWeapon::StartFire()
{
    FireInProgress = true;
}

void ASTUBaseWeapon::StopFire()
{
    FireInProgress = false;
}

bool ASTUBaseWeapon::IsFiring() const
{
    return FireInProgress;
}
```

* Also add a function to the weapon component:

```cpp
bool USTUWeaponComponent::IsFiring() const 
{ 
    return CurrentWeapon && CurrentWeapon->IsFiring(); 
}
```

* In the character class, we create the `OnStartFire` function and bind to it when firing is started:

```cpp
PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &ASTUPlayerCharacter::OnStartFire);
```

* After that, add the code for the `OnStartFire` function and update the other two functions:

```cpp
void ASTUPlayerCharacter::OnStartFire()
{
    if (IsRunning()) return;
    WeaponComponent->StartFire();
}

...

void ASTUPlayerCharacter::OnStartRunning()
{
    WantsToRun = true;
    if (IsRunning())
    {
        WeaponComponent->StopFire();
    }
}

...

void ASTUPlayerCharacter::MoveForward(float Amount)
{
    IsMovingForward = Amount > 0.0f;
    if (Amount == 0.0f) return;
    AddMovementInput(GetActorForwardVector(), Amount);

    if (IsRunning() && WeaponComponent->IsFiring())
    {
        WeaponComponent->StopFire();
    }
}
```

* Additional details with calling parent functions `StartFire` and `StopFire` can be found in the repository

[Commit in repository](https://github.com/life-exe/UnrealEngine/commit/78b3a997981a56f0935fc39ca6c25ebc4a998595)
