From aef9f87dbff5abed6e731cc55699ba5384bd5f6a Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 1 Feb 2024 20:08:18 +0000 Subject: [PATCH] Add Throw Explosive Animation Notifier --- .../NakatomiThrowExplosiveNotify.cpp | 15 +++++++++++ .../AnimNotify/NakatomiThrowExplosiveNotify.h | 21 +++++++++++++++ Source/Nakatomi/PlayerCharacter.cpp | 27 ++++++++++--------- Source/Nakatomi/PlayerCharacter.h | 5 ++++ 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 Source/Nakatomi/AnimNotify/NakatomiThrowExplosiveNotify.cpp create mode 100644 Source/Nakatomi/AnimNotify/NakatomiThrowExplosiveNotify.h diff --git a/Source/Nakatomi/AnimNotify/NakatomiThrowExplosiveNotify.cpp b/Source/Nakatomi/AnimNotify/NakatomiThrowExplosiveNotify.cpp new file mode 100644 index 0000000..994f83f --- /dev/null +++ b/Source/Nakatomi/AnimNotify/NakatomiThrowExplosiveNotify.cpp @@ -0,0 +1,15 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "../AnimNotify/NakatomiThrowExplosiveNotify.h" +#include "Nakatomi/PlayerCharacter.h" + +void UNakatomiThrowExplosiveNotify::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) +{ + APlayerCharacter* Character = Cast(MeshComp->GetOwner()); + + if (Character != nullptr) + { + Character->ThrowExplosive(); + } +} diff --git a/Source/Nakatomi/AnimNotify/NakatomiThrowExplosiveNotify.h b/Source/Nakatomi/AnimNotify/NakatomiThrowExplosiveNotify.h new file mode 100644 index 0000000..8b85854 --- /dev/null +++ b/Source/Nakatomi/AnimNotify/NakatomiThrowExplosiveNotify.h @@ -0,0 +1,21 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Animation/AnimNotifies/AnimNotify.h" +#include "NakatomiThrowExplosiveNotify.generated.h" + +/** + * + */ +UCLASS() +class NAKATOMI_API UNakatomiThrowExplosiveNotify : public UAnimNotify +{ + GENERATED_BODY() + +public: + + virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; + +}; diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index e35fc49..2b4ef49 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -731,21 +731,24 @@ void APlayerCharacter::ThrowExplosiveCallback() { if (ThrowableInventory.Num() > 0) { - PlayAnimMontage(ThrowAnimMontage); - - FVector Location; - FVector BoxExtent; - GetActorBounds(true, Location, BoxExtent, false); - - FVector SpawnLocation = (BoxExtent.X * GetActorForwardVector()) * 2; - SpawnLocation += Location; - SpawnLocation += (25.0f * GetActorForwardVector()); - SpawnLocation.Z += BoxExtent.Z; - - GetWorld()->SpawnActor(ThrowableInventory.Pop(), SpawnLocation, FRotator::ZeroRotator); + PlayAnimMontage(ThrowExplosiveAnimMontage); } } +void APlayerCharacter::ThrowExplosive() +{ + FVector Location; + FVector BoxExtent; + GetActorBounds(true, Location, BoxExtent, false); + + FVector SpawnLocation = (BoxExtent.X * GetActorForwardVector()) * 2; + SpawnLocation += Location; + SpawnLocation += (25.0f * GetActorForwardVector()); + SpawnLocation.Z += BoxExtent.Z; + + GetWorld()->SpawnActor(ThrowableInventory.Pop(), SpawnLocation, FRotator::ZeroRotator); +} + AThrowable* APlayerCharacter::ThrowThrowable() { FVector Location; diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index bb25444..801b8f7 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -85,6 +85,9 @@ public: UPROPERTY(EditDefaultsOnly) UAnimMontage* ThrowWeaponAnimMontage; + + UPROPERTY(EditDefaultsOnly) + UAnimMontage* ThrowExplosiveAnimMontage; protected: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) @@ -220,6 +223,8 @@ public: void ThrowWeapon(); void ThrowExplosiveCallback(); + + void ThrowExplosive(); AThrowable* ThrowThrowable();