I am trying to create a basic shooting turret and have one set up to shoot projectiles when my character enters the proximity area but so far I am only able to get it to fire a single time using OnOverlapBegin()
Is there a way to fire multiple times while my character is in the proximity area??
void ATurret::Prox_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult) {
FVector FireDirection = FVector(20,20,20);
// If we it's ok to fire again
if (bCanFire == true){
if (IsOverlappingActor(OtherActor) == true){
const FRotator FireRotation = FireDirection.Rotation();
const FVector SpawnLocation = GetActorLocation() + FireRotation.RotateVector(GunOffset);
UWorld* const World = GetWorld();
if (World != NULL){
// spawn the projectile
World->SpawnActor<ADOB_TowerDefenseProjectile>(SpawnLocation, FireRotation);
}
// try and play the sound if specified
if (FireSound != nullptr){
UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());
}
}
}
}
note “bCanFire” is always true