Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Source/SentryTower/Player/SentryTowerTurret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ASentryTowerProjectile>(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;

Expand Down