Updated CombatCharacter to Spawn GunEffect onClick

This commit is contained in:
Philip W 2023-01-31 01:48:35 +00:00
parent 45374da8bb
commit ed0bcc7c76
3 changed files with 18 additions and 2 deletions

Binary file not shown.

View File

@ -65,6 +65,16 @@ void UHoldToInitCombat::OnRightClickDown()
bRightClickDown = true;
//InitCombatWidget->AddToViewport();
}
if (GunEffect)
{
//Get Player Actor
const AActor* PlayerActor = GetWorld()->GetFirstPlayerController()->GetPawn();
//Get Static Mesh Location on the player actor
const UStaticMeshComponent* GunComponent = Cast<UStaticMeshComponent>(PlayerActor->GetComponentsByTag(UPrimitiveComponent::StaticClass(), FName("Gun"))[0]);
const FVector GunLocationOffset = GunComponent->GetSocketTransform("Muzzle").TransformPosition(FVector(-100, 0, 0));
UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), GunEffect, GunLocationOffset, PlayerActor->GetActorRotation());
}
}
void UHoldToInitCombat::OnRightClickUp()

View File

@ -4,8 +4,11 @@
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "NiagaraComponent.h"
#include "NiagaraFunctionLibrary.h"
#include "HoldToInitCombat.generated.h"
class UNiagaraSystem;
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class THE_TWILIGHT_ABYSS_API UHoldToInitCombat : public UActorComponent
@ -20,6 +23,9 @@ public:
UPROPERTY()
TSubclassOf<UUserWidget> InitCombatWidgetClass;
UPROPERTY(EditDefaultsOnly)
UNiagaraSystem* GunEffect;
protected:
// Called when the game starts
virtual void BeginPlay() override;