Not sure actually when the problem has appear, but i cannot solve it by myself.
The problem: FiringState enters “Reloading” state only with “initial” reloading when the game starts and there is not a “reloading” state for 3 secs after Firing(). So my bots firing every tick - looks like crazy bobm-sausage
TickComponent
void UTankAimingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction)
{
if (RoundsLeft <= 0)
{
FiringState = EFiringState::OutOfAmmo;
}
else if ((FPlatformTime::Seconds() - LastFireTime) < ReloadTimeInSeconds)
{
FiringState = EFiringState::Reloading;
}
else if (IsBarrelMoving())
{
FiringState = EFiringState::Aiming;
}
else
{
FiringState = EFiringState::Locked;
}
}
Fire() method
void UTankAimingComponent::Fire()
{
if ((FiringState == EFiringState::Locked) || (FiringState == EFiringState::Aiming))
{
if (!ensure(Barrel)) { return; }
if (!ensure(ProjectileBlueprint)) { return; }
auto Projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileBlueprint, Barrel->GetSocketLocation(FName("Projectile")), Barrel->GetSocketRotation(FName("Projectile")));
Projectile->LaunchProjectile(LaunchSpeed);
RoundsLeft--;
}
}