# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lifeexe-art.gitbook.io/unreal-engine-c-course-eng/lessons/lecture-065/blocking-shooting-while-running.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
