2022-05-20 16:12:50 +00:00
|
|
|
// 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();
|
2022-05-29 09:59:15 +00:00
|
|
|
|
2022-05-20 16:12:50 +00:00
|
|
|
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();
|
|
|
|
}
|