Add logic to Explode in Demolition Character

This commit is contained in:
Louis Hobbs 2023-06-14 22:57:44 +01:00
parent a67d4c671a
commit d8ca7f001c
2 changed files with 59 additions and 1 deletions

View File

@ -2,8 +2,50 @@
#include "DemolitionCharacter.h" #include "DemolitionCharacter.h"
#include <Kismet/GameplayStatics.h>
void ADemolitionCharacter::Explode() void ADemolitionCharacter::Explode()
{ {
UE_LOG(LogTemp, Warning, TEXT("BANG!")); GetHealthComponent()->TakeDamage(this, this->GetHealthComponent()->GetMaxHealth(), nullptr, nullptr, nullptr);
FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
if (ExplosionParticleSystem)
{
UGameplayStatics::SpawnEmitterAtLocation(this,
ExplosionParticleSystem,
this->ActorToWorld().GetLocation(),
FRotator::ZeroRotator,
true);
}
TArray<FOverlapResult> outOverlaps;
GetWorld()->OverlapMultiByObjectType(outOverlaps,
ActorToWorld().GetLocation(),
FQuat::Identity,
FCollisionObjectQueryParams::AllObjects,
FCollisionShape::MakeSphere(ExplosionRadius));
for (FOverlapResult Overlaps : outOverlaps)
{
if (auto healthComponent = Overlaps.GetActor()->GetComponentByClass<UHealthComponent>())
{
float distance = FVector::Distance(ActorToWorld().GetLocation(), Overlaps.GetActor()->ActorToWorld().GetLocation());
float scale = 1.f - (distance / ExplosionRadius);
healthComponent->TakeDamage(Overlaps.GetActor(), scale * MaxDamage, nullptr, nullptr, this);
}
}
if (FieldSystemActor)
{
FTransform transform;
transform.SetLocation(this->ActorToWorld().GetLocation());
auto field = GetWorld()->SpawnActor<AFieldSystemActor>(FieldSystemActor, transform, SpawnParameters);
if (field)
{
field->Destroy();
}
}
} }

View File

@ -14,6 +14,22 @@ class NAKATOMI_API ADemolitionCharacter : public AEnemyCharacter
{ {
GENERATED_BODY() GENERATED_BODY()
protected:
UPROPERTY(EditDefaultsOnly)
USoundBase* ExplosionSound;
UPROPERTY(EditDefaultsOnly)
TSubclassOf<class ANakatomiFieldSystemActor> FieldSystemActor;
UPROPERTY(EditDefaultsOnly)
UParticleSystem* ExplosionParticleSystem;
UPROPERTY(EditDefaultsOnly)
float ExplosionRadius = 500.f;
UPROPERTY(EditDefaultsOnly)
float MaxDamage = 150.f;
public: public:
UFUNCTION() UFUNCTION()