Move hit processing to `ProcessHits`

This commit is contained in:
Louis Hobbs 2023-03-13 21:47:42 +00:00
parent 187b067e88
commit 403eff6029
2 changed files with 25 additions and 16 deletions

View File

@ -252,24 +252,30 @@ void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
{
hits->Add(Result);
DrawDebugLine(GetWorld(), TraceStart, Result.ImpactPoint, FColor::Blue, true, 500, 0U, 0);
}
}
}
// TODO: Handle hits in a meaningful way
FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
{
for (FHitResult Hit : hits)
{
// TODO: Handle hits in a meaningful way
FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
// Spawn field actor
FTransform transform;
transform.SetLocation(Result.ImpactPoint);
auto field = GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters);
if (Result.GetActor())
// Spawn field actor
FTransform transform;
transform.SetLocation(Hit.ImpactPoint);
auto field = GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters);
if (Hit.GetActor())
{
if (Hit.GetActor()->ActorHasTag("Enemy"))
{
if (Result.GetActor()->ActorHasTag("Enemy"))
{
// TODO: Do thing
auto enemy = Cast<AEnemyCharacter>(Result.GetActor());
enemy->GetHealthComponent()->TakeDamage(Result.GetActor(),CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this);
}
// TODO: Do thing
auto enemy = Cast<AEnemyCharacter>(Hit.GetActor());
enemy->GetHealthComponent()->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this);
}
}
}
@ -300,6 +306,7 @@ void APlayerCharacter::OnFire()
TArray<FHitResult> Hits = TArray<FHitResult>();
CalculateHits(&Hits);
ProcessHits(Hits);
CurrentWeapon->DecrementAmmoCount(1);

View File

@ -114,7 +114,9 @@ public:
void SetWalkingCallback(const FInputActionInstance& Instance);
void CalculateHits(TArray<FHitResult>* hits);
virtual void CalculateHits(TArray<FHitResult>* hits) override;
virtual void ProcessHits(TArray<FHitResult> hits) override;
void WeaponSwitchingCallback(const FInputActionInstance& Instance);