play death animation

This commit is contained in:
Caleb Buhungiro
2025-09-12 22:54:24 +08:00
parent 4321696a33
commit cddfd8175c
8 changed files with 77 additions and 9 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -3,7 +3,10 @@
#include "Crunch/Public/Character/CCharacter.h" #include "Crunch/Public/Character/CCharacter.h"
#include "Components/CapsuleComponent.h"
#include "Components/WidgetComponent.h" #include "Components/WidgetComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GAS/CAbilitySystemComponent.h" #include "GAS/CAbilitySystemComponent.h"
#include "GAS/CAttributeSet.h" #include "GAS/CAttributeSet.h"
#include "GAS/UCAbilitySystemStatics.h" #include "GAS/UCAbilitySystemStatics.h"
@@ -125,12 +128,46 @@ void ACCharacter::UpdateHeadStatGaugeVisibility()
} }
} }
void ACCharacter::SetStatusGaugeEnabled(bool bIsEnabled)
{
GetWorldTimerManager().ClearTimer(HeadStatGaugeVisibilityUpdateTimerHandle);
if (bIsEnabled)
{
ConfigureOverHeadStatusWidget();
}
else
{
OverHeadWidgetComponent->SetHiddenInGame(true);
}
}
void ACCharacter::PlayDeathAnimation()
{
if (DeathMontage)
{
PlayAnimMontage(DeathMontage);
}
}
void ACCharacter::StartDeathSequence() void ACCharacter::StartDeathSequence()
{ {
UE_LOG(LogTemp, Warning, TEXT("----------------------------DEAD")); OnDead();
PlayDeathAnimation();
SetStatusGaugeEnabled(false);
GetCharacterMovement()->SetMovementMode(MOVE_None);
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
} }
void ACCharacter::ReSpawn() void ACCharacter::ReSpawn()
{ {
UE_LOG(LogTemp, Warning, TEXT("----------------------------Respawn")); OnRespawn();
}
void ACCharacter::OnDead()
{
}
void ACCharacter::OnRespawn()
{
} }

View File

@@ -92,6 +92,22 @@ void ACPlayerCharacter::HandleAbilityInput(const FInputActionValue& InputActionV
: AbilitySystemComponent->AbilityLocalInputReleased(static_cast<int32>(InputID)); : AbilitySystemComponent->AbilityLocalInputReleased(static_cast<int32>(InputID));
} }
void ACPlayerCharacter::OnDead()
{
if (const auto PlayerController { GetController<APlayerController>() })
{
DisableInput(PlayerController);
}
}
void ACPlayerCharacter::OnRespawn()
{
if (const auto PlayerController { GetController<APlayerController>() })
{
EnableInput(PlayerController);
}
}
FVector ACPlayerCharacter::GetLookRightDir() const FVector ACPlayerCharacter::GetLookRightDir() const
{ {
return ViewCamera->GetRightVector(); return ViewCamera->GetRightVector();

View File

@@ -57,10 +57,18 @@ private:
FTimerHandle HeadStatGaugeVisibilityUpdateTimerHandle; FTimerHandle HeadStatGaugeVisibilityUpdateTimerHandle;
void UpdateHeadStatGaugeVisibility(); void UpdateHeadStatGaugeVisibility();
void SetStatusGaugeEnabled(bool bIsEnabled);
/********************************************************************************************/ /********************************************************************************************/
/* Death & Respawning */ /* Death & Respawning */
/********************************************************************************************/ /********************************************************************************************/
UPROPERTY(EditDefaultsOnly, Category="Death")
TObjectPtr<UAnimMontage> DeathMontage;
void PlayDeathAnimation();
void StartDeathSequence(); void StartDeathSequence();
void ReSpawn(); void ReSpawn();
virtual void OnDead();
virtual void OnRespawn();
}; };

View File

@@ -55,5 +55,9 @@ private:
void HandleLookInput(const FInputActionValue& InputActionValue); void HandleLookInput(const FInputActionValue& InputActionValue);
void HandleMoveInput(const FInputActionValue& InputActionValue); void HandleMoveInput(const FInputActionValue& InputActionValue);
void HandleAbilityInput(const FInputActionValue& InputActionValue, ECAbilityInputID AbilityInputID); void HandleAbilityInput(const FInputActionValue& InputActionValue, ECAbilityInputID AbilityInputID);
/*************************************************************************************/
//------------------------- Death && Respawn-------------------------------------------
/*************************************************************************************/
virtual void OnDead() override;
virtual void OnRespawn() override;
}; };