blaster/Source/Blaster/Weapon/ProjectileGrenade.cpp

49 lines
1.3 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 (BounceSound)
{
UGameplayStatics::PlaySoundAtLocation(
this,
BounceSound,
GetActorLocation()
);
}
}
void AProjectileGrenade::Destroyed()
{
ExplodeDamage();
Super::Destroyed();
}