Add Throw Weapon Animation Notifier
This commit is contained in:
parent
d96a5c837a
commit
eaa81f4478
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
};
|
|
@ -703,27 +703,30 @@ void APlayerCharacter::ThrowWeaponCallback()
|
|||
{
|
||||
if (CurrentWeapon)
|
||||
{
|
||||
PlayAnimMontage(ThrowAnimMontage);
|
||||
|
||||
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();
|
||||
PlayAnimMontage(ThrowWeaponAnimMontage);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
if (ThrowableInventory.Num() > 0)
|
||||
|
|
|
@ -84,7 +84,7 @@ public:
|
|||
FOnEnemyHitDelegate OnEnemyHit;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
UAnimMontage* ThrowAnimMontage;
|
||||
UAnimMontage* ThrowWeaponAnimMontage;
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
|
@ -217,6 +217,8 @@ public:
|
|||
|
||||
void ThrowWeaponCallback();
|
||||
|
||||
void ThrowWeapon();
|
||||
|
||||
void ThrowExplosiveCallback();
|
||||
|
||||
AThrowable* ThrowThrowable();
|
||||
|
|
Loading…
Reference in New Issue