Play Hit Animation Montage when OnDamaged is called

This commit is contained in:
baz 2024-02-04 19:20:16 +00:00
parent c1afc827e0
commit 3134e269f7
2 changed files with 11 additions and 1 deletions

View File

@ -3,7 +3,6 @@
#include "PlayerCharacter.h" #include "PlayerCharacter.h"
// You can remove these, this is just to get intellisense to work // You can remove these, this is just to get intellisense to work
#include <string>
#include <Components/CapsuleComponent.h> #include <Components/CapsuleComponent.h>
#include <Kismet/GameplayStatics.h> #include <Kismet/GameplayStatics.h>
@ -444,6 +443,14 @@ void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
void APlayerCharacter::OnDamaged() void APlayerCharacter::OnDamaged()
{ {
Super::OnDamaged(); Super::OnDamaged();
int32 randomAnimMontage = FMath::RandRange(0,OnDamagedHitAnimMontages.Num()-1);
if (OnDamagedHitAnimMontages[randomAnimMontage] != nullptr)
{
//TODO: Disable movement while playing animation montage
PlayAnimMontage(OnDamagedHitAnimMontages[randomAnimMontage]);
}
} }
void APlayerCharacter::OnDeath() void APlayerCharacter::OnDeath()

View File

@ -89,6 +89,9 @@ public:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
UAnimMontage* ThrowExplosiveAnimMontage; UAnimMontage* ThrowExplosiveAnimMontage;
UPROPERTY(EditDefaultsOnly)
TArray<UAnimMontage*> OnDamagedHitAnimMontages;
protected: protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float SprintSpeedMultiplier = 2.0f; float SprintSpeedMultiplier = 2.0f;