Move hit processing to `ProcessHits`
This commit is contained in:
parent
187b067e88
commit
403eff6029
|
@ -252,24 +252,30 @@ void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
|
||||||
{
|
{
|
||||||
hits->Add(Result);
|
hits->Add(Result);
|
||||||
DrawDebugLine(GetWorld(), TraceStart, Result.ImpactPoint, FColor::Blue, true, 500, 0U, 0);
|
DrawDebugLine(GetWorld(), TraceStart, Result.ImpactPoint, FColor::Blue, true, 500, 0U, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
|
||||||
|
{
|
||||||
|
for (FHitResult Hit : hits)
|
||||||
|
{
|
||||||
// TODO: Handle hits in a meaningful way
|
// TODO: Handle hits in a meaningful way
|
||||||
FActorSpawnParameters SpawnParameters;
|
FActorSpawnParameters SpawnParameters;
|
||||||
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||||
|
|
||||||
// Spawn field actor
|
// Spawn field actor
|
||||||
FTransform transform;
|
FTransform transform;
|
||||||
transform.SetLocation(Result.ImpactPoint);
|
transform.SetLocation(Hit.ImpactPoint);
|
||||||
auto field = GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters);
|
auto field = GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters);
|
||||||
|
|
||||||
if (Result.GetActor())
|
if (Hit.GetActor())
|
||||||
{
|
{
|
||||||
if (Result.GetActor()->ActorHasTag("Enemy"))
|
if (Hit.GetActor()->ActorHasTag("Enemy"))
|
||||||
{
|
{
|
||||||
// TODO: Do thing
|
// TODO: Do thing
|
||||||
auto enemy = Cast<AEnemyCharacter>(Result.GetActor());
|
auto enemy = Cast<AEnemyCharacter>(Hit.GetActor());
|
||||||
enemy->GetHealthComponent()->TakeDamage(Result.GetActor(),CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this);
|
enemy->GetHealthComponent()->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,6 +306,7 @@ void APlayerCharacter::OnFire()
|
||||||
|
|
||||||
TArray<FHitResult> Hits = TArray<FHitResult>();
|
TArray<FHitResult> Hits = TArray<FHitResult>();
|
||||||
CalculateHits(&Hits);
|
CalculateHits(&Hits);
|
||||||
|
ProcessHits(Hits);
|
||||||
|
|
||||||
CurrentWeapon->DecrementAmmoCount(1);
|
CurrentWeapon->DecrementAmmoCount(1);
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,9 @@ public:
|
||||||
|
|
||||||
void SetWalkingCallback(const FInputActionInstance& Instance);
|
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);
|
void WeaponSwitchingCallback(const FInputActionInstance& Instance);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue