From 1274b3e50ce974cf393348de9b47cc332dbce1ec Mon Sep 17 00:00:00 2001 From: SAM-tak Date: Wed, 20 Mar 2024 02:07:13 +0900 Subject: [PATCH] Restored the position correction process during multiplayer --- Source/ALS/Private/AlsCharacter_Actions.cpp | 22 +++++++++++++++++++ .../Public/Settings/AlsRagdollingSettings.h | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/Source/ALS/Private/AlsCharacter_Actions.cpp b/Source/ALS/Private/AlsCharacter_Actions.cpp index a9559fa0f..9e04fc20e 100644 --- a/Source/ALS/Private/AlsCharacter_Actions.cpp +++ b/Source/ALS/Private/AlsCharacter_Actions.cpp @@ -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. diff --git a/Source/ALS/Public/Settings/AlsRagdollingSettings.h b/Source/ALS/Public/Settings/AlsRagdollingSettings.h index 46753d84f..6c1cf8836 100644 --- a/Source/ALS/Public/Settings/AlsRagdollingSettings.h +++ b/Source/ALS/Public/Settings/AlsRagdollingSettings.h @@ -34,6 +34,10 @@ struct ALS_API FAlsRagdollingSettings UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS") TObjectPtr 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")