Skip to content

Commit

Permalink
Integrated The physical animation component
Browse files Browse the repository at this point in the history
  • Loading branch information
SAM-tak committed Apr 6, 2024
1 parent 16059bc commit 0f42c80
Show file tree
Hide file tree
Showing 18 changed files with 1,217 additions and 206 deletions.
5 changes: 4 additions & 1 deletion Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ p.NetUsePackedMovementRPCs=1 ; Required for view network smoothing on the listen
a.URO.DisableInterpolation=1 ; If enabled, the character may jitter during rotation and foot locking will not be able to work properly.

[/Script/Engine.PhysicsSettings]
bTickPhysicsAsync=False ; If enabled, the character may fall through the ground when landing while the ragdoll is active.
bTickPhysicsAsync=False ; If enabled, the character may fall through the ground when landing while the ragdoll is active at low FPS. And, there is a new problem where the position of the kinematic bone significantly shifts when using the PhysicalAnimationComponent.
bSubstepping=True
bSubsteppingAsync=True
MaxSubsteps=12
Binary file not shown.
Binary file not shown.
Binary file modified Content/ALS/Character/AB_Als_Monolithic.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/ALS/Character/PA_Als.uasset
Binary file not shown.
43 changes: 37 additions & 6 deletions Source/ALS/Private/AlsAnimationInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ void UAlsAnimationInstance::RefreshTurnInPlace(const float DeltaTime)
}
}

if (IsValid(TurnInPlaceSettings) && ALS_ENSURE(IsValid(TurnInPlaceSettings->Animation)))
if (TurnInPlaceSettings && IsValid(TurnInPlaceSettings) && ALS_ENSURE(IsValid(TurnInPlaceSettings->Animation)))
{
// Animation montages can't be played in the worker thread, so queue them up to play later in the game thread.

Expand Down Expand Up @@ -1747,22 +1747,53 @@ void UAlsAnimationInstance::RefreshRagdollingOnGameThread()
return;
}

if (RagdollingState.bFreezed)
{
return;
}

// Scale the flail play rate by the root speed. The faster the ragdoll moves, the faster the character will flail.

static constexpr auto ReferenceSpeed{1000.0f};

RagdollingState.FlailPlayRate = UAlsMath::Clamp01(UE_REAL_TO_FLOAT(Character->GetRagdollingState().Velocity.Size() / ReferenceSpeed));
RagdollingState.FlailPlayRate = UAlsMath::Clamp01(UE_REAL_TO_FLOAT(Character->GetCharacterMovement()->Velocity.Size() / ReferenceSpeed));
}

FPoseSnapshot& UAlsAnimationInstance::SnapshotFinalRagdollPose()
FPoseSnapshot& UAlsAnimationInstance::GetFinalRagdollPoseSnapshot()
{
check(IsInGameThread())

// Save a snapshot of the current ragdoll pose for use in animation graph to blend out of the ragdoll.
return RagdollingState.FinalRagdollPose;
}

void UAlsAnimationInstance::FreezeRagdolling()
{
check(IsInGameThread())

SnapshotPose(RagdollingState.FinalRagdollPose);
if (!RagdollingState.bFreezed)
{
// Save a snapshot of the current ragdoll pose for use in animation graph to blend out of the ragdoll.
SnapshotPose(RagdollingState.FinalRagdollPose);

return RagdollingState.FinalRagdollPose;
RagdollingState.bFreezed = true;
}
}

void UAlsAnimationInstance::UnFreezeRagdolling()
{
check(IsInGameThread())

if (RagdollingState.bFreezed)
{
RagdollingState.bFreezed = false;
}
}

float UAlsAnimationInstance::GetRagdollingStartBlendTime() const
{
check(IsInGameThread())

return Settings->RagdollingStartBlendTime;
}

float UAlsAnimationInstance::GetCurveValueClamped01(const FName& CurveName) const
Expand Down
8 changes: 8 additions & 0 deletions Source/ALS/Private/AlsCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "AlsAnimationInstance.h"
#include "AlsCharacterMovementComponent.h"
#include "AlsPhysicalAnimationComponent.h"
#include "TimerManager.h"
#include "Components/CapsuleComponent.h"
#include "Components/SkeletalMeshComponent.h"
Expand All @@ -22,6 +23,8 @@ namespace AlsCharacterConstants
constexpr auto TeleportDistanceThresholdSquared{FMath::Square(50.0f)};
}

FName AAlsCharacter::PhysicalAnimationComponentName(TEXT("PhysicalAnimComp"));

AAlsCharacter::AAlsCharacter(const FObjectInitializer& ObjectInitializer) : Super{
ObjectInitializer.SetDefaultSubobjectClass<UAlsCharacterMovementComponent>(CharacterMovementComponentName)
}
Expand All @@ -44,6 +47,8 @@ AAlsCharacter::AAlsCharacter(const FObjectInitializer& ObjectInitializer) : Supe

AlsCharacterMovement = Cast<UAlsCharacterMovementComponent>(GetCharacterMovement());

PhysicalAnimation = CreateDefaultSubobject<UAlsPhysicalAnimationComponent>(PhysicalAnimationComponentName);

// This will prevent the editor from combining component details with actor details.
// Component details can still be accessed from the actor's component hierarchy.

Expand Down Expand Up @@ -137,6 +142,8 @@ void AAlsCharacter::PostInitializeComponents()

AnimationInstance = Cast<UAlsAnimationInstance>(GetMesh()->GetAnimInstance());

PhysicalAnimation->SetSkeletalMeshComponent(GetMesh());

Super::PostInitializeComponents();
}

Expand Down Expand Up @@ -289,6 +296,7 @@ void AAlsCharacter::Tick(const float DeltaTime)
RefreshMantling();
RefreshRagdolling(DeltaTime);
RefreshRolling(DeltaTime);
PhysicalAnimation->Refresh(this);

Super::Tick(DeltaTime);

Expand Down
Loading

0 comments on commit 0f42c80

Please sign in to comment.