Skip to content

Commit

Permalink
Restored the position correction process during multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
SAM-tak committed Mar 19, 2024
1 parent 904d8b1 commit 1274b3e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Source/ALS/Private/AlsCharacter_Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,28 @@ void AAlsCharacter::RefreshRagdolling(const float DeltaTime)
RagdollingState.bGrounded = bGrounded;
SetActorLocation(NewActorLocation, true);

// Zero target location means that it hasn't been replicated yet, so we can't apply the logic below.

if (!bLocallyControlled && !RagdollTargetLocation.IsZero())
{
// Apply ragdoll location corrections.

auto PelvisLocation{GetMesh()->GetBoneLocation(UAlsConstants::PelvisBoneName())};

auto NewPelvisLocation{
FMath::VInterpTo(PelvisLocation, RagdollTargetLocation, DeltaTime, Settings->Ragdolling.SimulatedProxyMeshInterpolationSpeed)
};

auto Diff{NewPelvisLocation - PelvisLocation};

for (auto& Body : GetMesh()->Bodies)
{
auto Transform{Body->GetUnrealWorldTransform()};
Transform.SetLocation(Transform.GetLocation() + Diff);
Body->SetBodyTransform(Transform, ETeleportType::TeleportPhysics);
}
}

if (IsRagdollingGroundedAndAged())
{
// Determine whether the ragdoll is facing upward or downward.
Expand Down
4 changes: 4 additions & 0 deletions Source/ALS/Public/Settings/AlsRagdollingSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct ALS_API FAlsRagdollingSettings
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS")
TObjectPtr<UAnimMontage> GetUpBackMontage{nullptr};

// for correction in multiplayer
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS")
float SimulatedProxyMeshInterpolationSpeed{10.0f};

// If checked, it stops the physical simulation and returns control of the bone to kinematic
// when the conditions mentioned later are met.
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS")
Expand Down

0 comments on commit 1274b3e

Please sign in to comment.