134 - Beam Particles

This commit is contained in:
Kingsmedia 2022-05-19 19:35:20 +02:00
parent d6557fb499
commit 05ea304d46
6 changed files with 30 additions and 13 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,6 +6,7 @@
#include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Character/BlasterCharacter.h"
#include "Engine/SkeletalMeshSocket.h" #include "Engine/SkeletalMeshSocket.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "Particles/ParticleSystemComponent.h"
void AHitScanWeapon::Fire(const FVector& HitTarget) void AHitScanWeapon::Fire(const FVector& HitTarget)
{ {
@ -16,7 +17,7 @@ void AHitScanWeapon::Fire(const FVector& HitTarget)
AController* InstigatorController = OwnerPawn->GetController(); AController* InstigatorController = OwnerPawn->GetController();
const USkeletalMeshSocket* MuzzleFlashSocket = GetWeaponMesh()->GetSocketByName("MuzzleFlash"); const USkeletalMeshSocket* MuzzleFlashSocket = GetWeaponMesh()->GetSocketByName("MuzzleFlash");
if (MuzzleFlashSocket && InstigatorController) if (MuzzleFlashSocket)
{ {
FTransform SocketTransform = MuzzleFlashSocket->GetSocketTransform(GetWeaponMesh()); FTransform SocketTransform = MuzzleFlashSocket->GetSocketTransform(GetWeaponMesh());
FVector Start = SocketTransform.GetLocation(); FVector Start = SocketTransform.GetLocation();
@ -32,21 +33,20 @@ void AHitScanWeapon::Fire(const FVector& HitTarget)
End, End,
ECC_Visibility ECC_Visibility
); );
FVector BeamEnd = End;
if (FireHit.bBlockingHit) if (FireHit.bBlockingHit)
{ {
BeamEnd = FireHit.ImpactPoint;
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(FireHit.GetActor()); ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(FireHit.GetActor());
if (BlasterCharacter) if (BlasterCharacter && HasAuthority() && InstigatorController)
{ {
if (HasAuthority()) UGameplayStatics::ApplyDamage(
{ BlasterCharacter,
UGameplayStatics::ApplyDamage( Damage,
BlasterCharacter, InstigatorController,
Damage, this,
InstigatorController, UDamageType::StaticClass()
this, );
UDamageType::StaticClass()
);
}
} }
if (ImpactParticles) if (ImpactParticles)
@ -59,6 +59,19 @@ void AHitScanWeapon::Fire(const FVector& HitTarget)
); );
} }
} }
if (BeamParticles)
{
UParticleSystemComponent* Beam = UGameplayStatics::SpawnEmitterAtLocation(
World,
BeamParticles,
SocketTransform
);
if (Beam)
{
Beam->SetVectorParameter(FName("Target"), BeamEnd);
}
}
} }
} }
} }

View File

@ -24,5 +24,9 @@ private:
float Damage = 20.f; float Damage = 20.f;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
class UParticleSystem* ImpactParticles; UParticleSystem* ImpactParticles;
UPROPERTY(EditAnywhere)
UParticleSystem* BeamParticles;
}; };