Skip to content

Commit 81768be

Browse files
authored
Merge pull request #213 from eddieataberk/patch-1
Restores velocities after recreating physics state
2 parents 1fe401f + c4ffa62 commit 81768be

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Source/RuntimeMeshComponent/Private/RuntimeMeshComponent.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,25 @@ FRuntimeMeshCollisionHitInfo URuntimeMeshComponent::GetHitSource(int32 FaceIndex
7171
void URuntimeMeshComponent::NewCollisionMeshReceived()
7272
{
7373
SCOPE_CYCLE_COUNTER(STAT_RuntimeMeshComponent_NewCollisionMeshReceived);
74+
75+
if (KeepMomentumOnCollisionUpdate)
76+
{
77+
// First Store Velocities
78+
FVector PrevLinearVelocity = GetPhysicsLinearVelocity();
79+
FVector PrevAngularVelocity = GetPhysicsAngularVelocityInDegrees();
7480

75-
// First recreate the physics state
76-
RecreatePhysicsState();
81+
// Recreate the physics state
82+
RecreatePhysicsState();
83+
84+
// Apply Velocities
85+
SetPhysicsLinearVelocity(PrevLinearVelocity, false);
86+
SetPhysicsAngularVelocityInDegrees(PrevAngularVelocity, false);
87+
}
88+
else
89+
{
90+
//First recreate the physics state
91+
RecreatePhysicsState();
92+
}
7793

7894
// Now update the navigation.
7995
FNavigationSystem::UpdateComponentData(*this);
@@ -240,4 +256,4 @@ void URuntimeMeshComponent::OnUnregister()
240256
}
241257

242258
Super::OnUnregister();
243-
}
259+
}

Source/RuntimeMeshComponent/Public/RuntimeMeshComponent.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
2929

3030
public:
3131
URuntimeMeshComponent();
32+
33+
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RuntimeMesh")
34+
bool KeepMomentumOnCollisionUpdate = false;
3235

3336
uint32 GetRuntimeMeshId() const { return RuntimeMeshReference? RuntimeMeshReference->GetMeshId() : -1; }
3437

0 commit comments

Comments
 (0)