Fix vehicles simulation instability when physics substepping is enabled
#2796
This commit is contained in:
@@ -1606,6 +1606,24 @@ PxMaterial* PhysicsBackendPhysX::GetDefaultMaterial()
|
||||
return DefaultMaterial;
|
||||
}
|
||||
|
||||
void PhysicsBackendPhysX::SimulationStepDone(PxScene* scene, float dt)
|
||||
{
|
||||
#if WITH_VEHICLE
|
||||
ScenePhysX* scenePhysX = nullptr;
|
||||
for (auto e : Physics::Scenes)
|
||||
{
|
||||
if (((ScenePhysX*)e->GetPhysicsScene())->Scene == scene)
|
||||
{
|
||||
scenePhysX = (ScenePhysX*)e->GetPhysicsScene();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!scenePhysX)
|
||||
return;
|
||||
scenePhysX->UpdateVehicles(dt);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PhysicsBackend::Init()
|
||||
{
|
||||
#define CHECK_INIT(value, msg) if (!value) { LOG(Error, msg); return true; }
|
||||
@@ -1895,10 +1913,6 @@ void PhysicsBackend::EndSimulateScene(void* scene)
|
||||
scenePhysX->Stepper.wait(scenePhysX->Scene);
|
||||
}
|
||||
|
||||
#if WITH_VEHICLE
|
||||
scenePhysX->UpdateVehicles(scenePhysX->LastDeltaTime);
|
||||
#endif
|
||||
|
||||
{
|
||||
PROFILE_CPU_NAMED("Physics.FlushActiveTransforms");
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
static PxCooking* GetCooking();
|
||||
#endif
|
||||
static PxMaterial* GetDefaultMaterial();
|
||||
static void SimulationStepDone(PxScene* scene, float dt);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#if COMPILE_WITH_PHYSX
|
||||
|
||||
#include "PhysicsStepperPhysX.h"
|
||||
#include "Engine/Physics/Physics.h"
|
||||
#include "PhysicsBackendPhysX.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include <ThirdParty/PhysX/foundation/PxMath.h>
|
||||
#include <ThirdParty/PhysX/PxSceneLock.h>
|
||||
@@ -66,7 +66,7 @@ void MultiThreadStepper::substepDone(StepperTask* ownerTask)
|
||||
}
|
||||
|
||||
// -> OnSubstep
|
||||
//Physics::OnSubstep();
|
||||
PhysicsBackendPhysX::SimulationStepDone(mScene, mSubStepSize);
|
||||
|
||||
if (mCurrentSubStep >= mNbSubSteps)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user