How to use Substepping in C++?
I only want to use AddForce() with a curve movement . if I turn on Substepping option in low Frame rate AddForce() it's going to be so faster. if I turn it off in very low (under 30 ) frame I can see a 10 % difference to 120 frames. I tried to use Substepping but it getting everything worse.
I tried to use this code :
In the tick of component which you want to access sub-steps from the game, do this: Code:
void URailroadWheelComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// Add custom physics forces each tick
This will call the delegate 'OnCalculateCustomPhysics' during next tick, for each substep (16 times for 16 substeps). Define delegate as: Code:
The delegate body is: Code:
void UTrainPhysicsSimulator::CustomPhysics(float DeltaTime, FBodyInstance* BodyInstance)
URailroadWheelComponent* RailroadWheelComponent = Cast<URailroadWheelComponent>(BodyInstance->OwnerComponent.Get());
if (!RailroadWheelComponent) return;
// Calculate custom forces
// You will have to apply forces directly to PhysX body if you want to apply forces! If you want to read body coordinates, read them from PhysX bodies! This is important for sub-steps as transformations aren't updated until end of physics tick
PxRigidBody* PRigidBody = BodyInstance->GetPxRigidBody();
PxTransform PTransform = PRigidBody->getGlobalPose();
PxVec3 PVelocity = PRigidBody->getLinearVelocity();
PxVec3 PAngVelocity = PRigidBody->getAngularVelocity();
PRigidBody->addForce(PForce, PxForceMode::eFORCE, true);
PRigidBody->addTorque(PTorque, PxForceMode::eFORCE, true);
from this page: https://forums.unrealengine.com/unreal-engine/announcements-and-releases/4148-physics-sub-stepping
but there is no effect.
looking forward to your helps.
Apr 19 '19 at 02:04 PM
in C++ Programming