enable ragdoll on death
This commit is contained in:
@@ -18,6 +18,7 @@ void ACCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
ConfigureOverHeadStatusWidget();
|
||||
MeshRelativeTransform = GetMesh()->GetRelativeTransform();
|
||||
}
|
||||
|
||||
ACCharacter::ACCharacter()
|
||||
@@ -145,10 +146,39 @@ void ACCharacter::PlayDeathAnimation()
|
||||
{
|
||||
if (DeathMontage)
|
||||
{
|
||||
PlayAnimMontage(DeathMontage);
|
||||
const auto MontageDuration {PlayAnimMontage(DeathMontage)};
|
||||
GetWorldTimerManager().SetTimer(
|
||||
DeathMontageTimerHandle,
|
||||
this,
|
||||
&ThisClass::DeathMontageFinished,
|
||||
MontageDuration + DeathMontageFinishTimeShift
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void ACCharacter::DeathMontageFinished()
|
||||
{
|
||||
SetRagdollEnabled(true);
|
||||
}
|
||||
|
||||
void ACCharacter::SetRagdollEnabled(bool bIsEnabled)
|
||||
{
|
||||
if (bIsEnabled)
|
||||
{
|
||||
GetMesh()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
|
||||
GetMesh()->SetSimulatePhysics(true);
|
||||
GetMesh()->SetCollisionEnabled(ECollisionEnabled::PhysicsOnly);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetMesh()->SetSimulatePhysics(false);
|
||||
GetMesh()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||
GetMesh()->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
|
||||
GetMesh()->SetRelativeTransform(MeshRelativeTransform);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ACCharacter::StartDeathSequence()
|
||||
{
|
||||
OnDead();
|
||||
@@ -162,6 +192,7 @@ void ACCharacter::StartDeathSequence()
|
||||
void ACCharacter::ReSpawn()
|
||||
{
|
||||
OnRespawn();
|
||||
SetRagdollEnabled(false);
|
||||
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
|
||||
GetCharacterMovement()->SetMovementMode(MOVE_Walking);
|
||||
GetMesh()->GetAnimInstance()->StopAllMontages(0.f);
|
||||
|
||||
@@ -62,9 +62,16 @@ private:
|
||||
/********************************************************************************************/
|
||||
/* Death & Respawning */
|
||||
/********************************************************************************************/
|
||||
FTransform MeshRelativeTransform;
|
||||
UPROPERTY(EditDefaultsOnly, Category="Death")
|
||||
float DeathMontageFinishTimeShift { -0.8f };
|
||||
UPROPERTY(EditDefaultsOnly, Category="Death")
|
||||
TObjectPtr<UAnimMontage> DeathMontage;
|
||||
|
||||
FTimerHandle DeathMontageTimerHandle;
|
||||
void DeathMontageFinished();
|
||||
void SetRagdollEnabled(bool bIsEnabled);
|
||||
|
||||
void PlayDeathAnimation();
|
||||
|
||||
void StartDeathSequence();
|
||||
|
||||
Reference in New Issue
Block a user