64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "Explosive.h"
|
|
|
|
#include "Components/SphereComponent.h"
|
|
#include "GameFramework/Character.h"
|
|
#include "Kismet/GameplayStatics.h"
|
|
#include "Sound/SoundCue.h"
|
|
#include "Particles/ParticleSystemComponent.h"
|
|
|
|
// Sets default values
|
|
AExplosive::AExplosive() :
|
|
Damage(40.f)
|
|
{
|
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
ExplosiveMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ExplosiveMesh"));
|
|
SetRootComponent(ExplosiveMesh);
|
|
|
|
OverlapSphere = CreateDefaultSubobject<USphereComponent>(TEXT("OverlapSphere"));
|
|
OverlapSphere->SetupAttachment(GetRootComponent());
|
|
}
|
|
|
|
// Called when the game starts or when spawned
|
|
void AExplosive::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
}
|
|
|
|
// Called every frame
|
|
void AExplosive::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick(DeltaTime);
|
|
|
|
}
|
|
|
|
void AExplosive::BulletHit_Implementation(FHitResult HitResult, AActor* Shooter, AController* ShooterController)
|
|
{
|
|
if (ExplosionSound)
|
|
{
|
|
UGameplayStatics::PlaySoundAtLocation(this, ExplosionSound, GetActorLocation());
|
|
}
|
|
|
|
if (ExplosionParticles)
|
|
{
|
|
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ExplosionParticles, HitResult.Location, FRotator(0.f), true);
|
|
}
|
|
|
|
// Apply explosive damage
|
|
TArray<AActor*> OverlappingActors;
|
|
GetOverlappingActors(OverlappingActors, ACharacter::StaticClass());
|
|
|
|
for (auto Actor : OverlappingActors)
|
|
{
|
|
UGameplayStatics::ApplyDamage(Actor, Damage, ShooterController, Shooter, UDamageType::StaticClass());
|
|
}
|
|
|
|
Destroy();
|
|
}
|
|
|