enable ragdoll on death
This commit is contained in:
Binary file not shown.
@@ -18,6 +18,7 @@ void ACCharacter::BeginPlay()
|
|||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
ConfigureOverHeadStatusWidget();
|
ConfigureOverHeadStatusWidget();
|
||||||
|
MeshRelativeTransform = GetMesh()->GetRelativeTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
ACCharacter::ACCharacter()
|
ACCharacter::ACCharacter()
|
||||||
@@ -145,10 +146,39 @@ void ACCharacter::PlayDeathAnimation()
|
|||||||
{
|
{
|
||||||
if (DeathMontage)
|
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()
|
void ACCharacter::StartDeathSequence()
|
||||||
{
|
{
|
||||||
OnDead();
|
OnDead();
|
||||||
@@ -162,6 +192,7 @@ void ACCharacter::StartDeathSequence()
|
|||||||
void ACCharacter::ReSpawn()
|
void ACCharacter::ReSpawn()
|
||||||
{
|
{
|
||||||
OnRespawn();
|
OnRespawn();
|
||||||
|
SetRagdollEnabled(false);
|
||||||
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
|
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
|
||||||
GetCharacterMovement()->SetMovementMode(MOVE_Walking);
|
GetCharacterMovement()->SetMovementMode(MOVE_Walking);
|
||||||
GetMesh()->GetAnimInstance()->StopAllMontages(0.f);
|
GetMesh()->GetAnimInstance()->StopAllMontages(0.f);
|
||||||
|
|||||||
@@ -62,9 +62,16 @@ private:
|
|||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
/* Death & Respawning */
|
/* Death & Respawning */
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
FTransform MeshRelativeTransform;
|
||||||
|
UPROPERTY(EditDefaultsOnly, Category="Death")
|
||||||
|
float DeathMontageFinishTimeShift { -0.8f };
|
||||||
UPROPERTY(EditDefaultsOnly, Category="Death")
|
UPROPERTY(EditDefaultsOnly, Category="Death")
|
||||||
TObjectPtr<UAnimMontage> DeathMontage;
|
TObjectPtr<UAnimMontage> DeathMontage;
|
||||||
|
|
||||||
|
FTimerHandle DeathMontageTimerHandle;
|
||||||
|
void DeathMontageFinished();
|
||||||
|
void SetRagdollEnabled(bool bIsEnabled);
|
||||||
|
|
||||||
void PlayDeathAnimation();
|
void PlayDeathAnimation();
|
||||||
|
|
||||||
void StartDeathSequence();
|
void StartDeathSequence();
|
||||||
|
|||||||
Reference in New Issue
Block a user