x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

how use Substepping ?

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
     GetBodyInstance()->AddCustomPhysics(OnCalculateCustomPhysics);
 }

This will call the delegate 'OnCalculateCustomPhysics' during next tick, for each substep (16 times for 16 substeps). Define delegate as: Code:

 FCalculateCustomPhysics OnCalculateCustomPhysics;
 OnCalculateCustomPhysics.BindUObject(this, &UTrainPhysicsSimulator::CustomPhysics);

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.

Thanks.

Product Version: UE 4.19
Tags:
more ▼

asked Apr 19 '19 at 02:04 PM in C++ Programming

avatar image

AAriyAA
69 5 9 15

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question