67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||
|
|
||
|
|
||
|
#include "ProjectileGrenade.h"
|
||
|
|
||
|
#include "Blaster/Character/BlasterCharacter.h"
|
||
|
#include "GameFramework/ProjectileMovementComponent.h"
|
||
|
#include "Kismet/GameplayStatics.h"
|
||
|
#include "Sound/SoundCue.h"
|
||
|
|
||
|
AProjectileGrenade::AProjectileGrenade()
|
||
|
{
|
||
|
ProjectileMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Grenade Mesh"));
|
||
|
ProjectileMesh->SetupAttachment(RootComponent);
|
||
|
ProjectileMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||
|
|
||
|
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
|
||
|
ProjectileMovementComponent->bRotationFollowsVelocity = true;
|
||
|
ProjectileMovementComponent->SetIsReplicated(true);
|
||
|
ProjectileMovementComponent->bShouldBounce = true;
|
||
|
}
|
||
|
|
||
|
void AProjectileGrenade::BeginPlay()
|
||
|
{
|
||
|
AActor::BeginPlay();
|
||
|
|
||
|
SpawnTrailSystem();
|
||
|
StartDestroyTimer();
|
||
|
ProjectileMovementComponent->OnProjectileBounce.AddDynamic(this, &AProjectileGrenade::OnBounce);
|
||
|
}
|
||
|
|
||
|
void AProjectileGrenade::OnBounce(const FHitResult& ImpactResult, const FVector& ImpactVelocity)
|
||
|
{
|
||
|
if (ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(ImpactResult.GetActor()))
|
||
|
{
|
||
|
const APawn* FiringPawn = GetInstigator();
|
||
|
if (FiringPawn && HasAuthority())
|
||
|
{
|
||
|
AController* InstigatorController = FiringPawn->GetController();
|
||
|
if (InstigatorController)
|
||
|
{
|
||
|
UGameplayStatics::ApplyDamage(
|
||
|
BlasterCharacter,
|
||
|
Damage / 4,
|
||
|
InstigatorController,
|
||
|
this,
|
||
|
UDamageType::StaticClass()
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (BounceSound)
|
||
|
{
|
||
|
UGameplayStatics::PlaySoundAtLocation(
|
||
|
this,
|
||
|
BounceSound,
|
||
|
GetActorLocation()
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void AProjectileGrenade::Destroyed()
|
||
|
{
|
||
|
ExplodeDamage();
|
||
|
Super::Destroyed();
|
||
|
}
|