diff --git a/Source/SentryTower/Player/SentryTowerTurret.cpp b/Source/SentryTower/Player/SentryTowerTurret.cpp index e243d73..fdedd6c 100644 --- a/Source/SentryTower/Player/SentryTowerTurret.cpp +++ b/Source/SentryTower/Player/SentryTowerTurret.cpp @@ -55,20 +55,33 @@ void ASentryTowerTurret::BeginPlay() void ASentryTowerTurret::Shoot(AActor* TargetActor, const FVector& TargetLocation) { - float CurrentTime = GetWorld()->GetTimeSeconds(); - if (CurrentTime - LastShotTime < AttackCooldown) + if (!ProjectileType) { + UE_LOG(LogTemp, Warning, TEXT("Turret %s has no projectile type set, skipping shoot"), *GetName()); return; } - LastShotTime = CurrentTime; + const float CurrentTime = GetWorld()->GetTimeSeconds(); + if (CurrentTime - LastShotTime < AttackCooldown) + { + return; + } - FVector SpawnLocation = ProjectileSocket->GetComponentLocation(); - FRotator SpawnRotation = TurretWeapon->GetComponentRotation(); + const FVector SpawnLocation = ProjectileSocket->GetComponentLocation(); + const FRotator SpawnRotation = TurretWeapon->GetComponentRotation(); - auto Projectile = + auto Projectile = Cast(GetWorld()->SpawnActor(ProjectileType, &SpawnLocation, &SpawnRotation)); + if (!Projectile) + { + UE_LOG(LogTemp, Warning, TEXT("Turret %s failed to spawn projectile of type %s"), + *GetName(), *ProjectileType->GetName()); + return; + } + + LastShotTime = CurrentTime; + Projectile->TargetToFollow = TargetActor; Projectile->TargetStationary = TargetLocation;