Add Throw Weapon Animation Notifier

This commit is contained in:
baz 2024-02-01 20:08:00 +00:00
parent d96a5c837a
commit eaa81f4478
4 changed files with 60 additions and 19 deletions

View File

@ -0,0 +1,16 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "../AnimNotify/NakatomiThrowWeaponNotify.h"
#include "Nakatomi/PlayerCharacter.h"
void UNakatomiThrowWeaponNotify::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
{
APlayerCharacter* Character = Cast<APlayerCharacter>(MeshComp->GetOwner());
if (Character != nullptr)
{
Character->ThrowWeapon();
}
}

View File

@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Animation/AnimNotifies/AnimNotify.h"
#include "NakatomiThrowWeaponNotify.generated.h"
/**
*
*/
UCLASS()
class NAKATOMI_API UNakatomiThrowWeaponNotify : public UAnimNotify
{
GENERATED_BODY()
public:
virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;
};

View File

@ -703,27 +703,30 @@ void APlayerCharacter::ThrowWeaponCallback()
{ {
if (CurrentWeapon) if (CurrentWeapon)
{ {
PlayAnimMontage(ThrowAnimMontage); PlayAnimMontage(ThrowWeaponAnimMontage);
FVector Location;
FVector BoxExtent;
GetActorBounds(true, Location, BoxExtent, false);
FVector SpawnLocation = (BoxExtent.X * GetActorForwardVector()) * 2;
SpawnLocation += Location;
SpawnLocation.Z += BoxExtent.Z;
TSubclassOf<AWeaponThrowable> WeaponThrowableTemplate = CurrentWeapon->GetWeaponThrowableTemplate();
AWeaponThrowable* Throwable = GetWorld()->SpawnActor<AWeaponThrowable>(
WeaponThrowableTemplate, SpawnLocation, FRotator::ZeroRotator);
Throwable->SetWeaponSkeletalMesh(GetCurrentWeapon()->GetSkeletalMesh());
RemoveCurrentWeaponFromInventory();
} }
} }
void APlayerCharacter::ThrowWeapon()
{
FVector Location;
FVector BoxExtent;
GetActorBounds(true, Location, BoxExtent, false);
FVector SpawnLocation = (BoxExtent.X * GetActorForwardVector()) * 2;
SpawnLocation += Location;
SpawnLocation.Z += BoxExtent.Z;
TSubclassOf<AWeaponThrowable> WeaponThrowableTemplate = CurrentWeapon->GetWeaponThrowableTemplate();
AWeaponThrowable* Throwable = GetWorld()->SpawnActor<AWeaponThrowable>(
WeaponThrowableTemplate, SpawnLocation, FRotator::ZeroRotator);
Throwable->SetWeaponSkeletalMesh(GetCurrentWeapon()->GetSkeletalMesh());
RemoveCurrentWeaponFromInventory();
}
void APlayerCharacter::ThrowExplosiveCallback() void APlayerCharacter::ThrowExplosiveCallback()
{ {
if (ThrowableInventory.Num() > 0) if (ThrowableInventory.Num() > 0)

View File

@ -84,7 +84,7 @@ public:
FOnEnemyHitDelegate OnEnemyHit; FOnEnemyHitDelegate OnEnemyHit;
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
UAnimMontage* ThrowAnimMontage; UAnimMontage* ThrowWeaponAnimMontage;
protected: protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
@ -217,6 +217,8 @@ public:
void ThrowWeaponCallback(); void ThrowWeaponCallback();
void ThrowWeapon();
void ThrowExplosiveCallback(); void ThrowExplosiveCallback();
AThrowable* ThrowThrowable(); AThrowable* ThrowThrowable();