Skip to content

Commit

Permalink
Merge pull request #213 from eddieataberk/patch-1
Browse files Browse the repository at this point in the history
Restores velocities after recreating physics state
  • Loading branch information
Moddingear authored May 16, 2021
2 parents 1fe401f + c4ffa62 commit 81768be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Source/RuntimeMeshComponent/Private/RuntimeMeshComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,25 @@ FRuntimeMeshCollisionHitInfo URuntimeMeshComponent::GetHitSource(int32 FaceIndex
void URuntimeMeshComponent::NewCollisionMeshReceived()
{
SCOPE_CYCLE_COUNTER(STAT_RuntimeMeshComponent_NewCollisionMeshReceived);

if (KeepMomentumOnCollisionUpdate)
{
// First Store Velocities
FVector PrevLinearVelocity = GetPhysicsLinearVelocity();
FVector PrevAngularVelocity = GetPhysicsAngularVelocityInDegrees();

// First recreate the physics state
RecreatePhysicsState();
// Recreate the physics state
RecreatePhysicsState();

// Apply Velocities
SetPhysicsLinearVelocity(PrevLinearVelocity, false);
SetPhysicsAngularVelocityInDegrees(PrevAngularVelocity, false);
}
else
{
//First recreate the physics state
RecreatePhysicsState();
}

// Now update the navigation.
FNavigationSystem::UpdateComponentData(*this);
Expand Down Expand Up @@ -240,4 +256,4 @@ void URuntimeMeshComponent::OnUnregister()
}

Super::OnUnregister();
}
}
3 changes: 3 additions & 0 deletions Source/RuntimeMeshComponent/Public/RuntimeMeshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu

public:
URuntimeMeshComponent();

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "RuntimeMesh")
bool KeepMomentumOnCollisionUpdate = false;

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

Expand Down

0 comments on commit 81768be

Please sign in to comment.