// 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(TEXT("Grenade Mesh")); ProjectileMesh->SetupAttachment(RootComponent); ProjectileMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision); ProjectileMovementComponent = CreateDefaultSubobject(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(); }