Hi, I have been working on a racer that moves exclusively through calls to AddForce and AddTorque. Things are going pretty well and I have built a fun little racer but I have some issues and concerns.
I should start by laying out how my racer works. It is a blueprint pawn with the following component hierarchy (there’s more to it but these are the relevant components):
(Scene component) - Root
–(Static mesh component) - Physics simulation is enabled
----(Racing simulation component) - programmed in c++
The racing simulation component is coded roughly like this:
Tick()
{
parentComponent->AddForce(gasInput * MaxGasStrength);
//...
FVector currentLinearVelocity = parentComponent->GetPhysicsLinearVelocity();
FVector hoverForce1 = CalculateHoverForce(currentLinearVelocity , lineTraces, etc);
parentComponent->AddForce(hoverForce1);
FVector currentLinearVelocity = parentComponent->GetPhysicsLinearVelocity();
FVector hoverForce2 = CalculateHoverForce(currentLinearVelocity , lineTraces, etc);
parentComponent->AddForce(hoverForce2);
//...
FVector currentAngularVelocity = parentComponent->GetPhysicsAngularVelocity();
FVector yawTorque = CalculateYawTorque(currentAngularVelocity , lineTraces, etc);
parentComponent->AddForce(yawTorque);
//...
}
Each frame I make around 10 AddForce calls and 2 to 4 AddTorque calls.
Questions/Concerns:
-
I have experimented with turning on physics sub-stepping and I am getting strange results. The racer behaves similarly for linear movement but differently for angular movement. I suspect that this might go away if I were to only call GetPhysicsLinearVelocity and GetPhysicsAngularVelocity once at the beginning of the tick and if I then applied all forces sequentially at the end of the tick. However, I tried this once without substepping enabled and the racer behaved erratically. This leads to another question.
-
Do calls to GetPhysics…Velocity on the same tick ever produce a different value? If so, can a call to AddForce be responsible?
My gut says that the answer should be no when sub stepping is off and yes when sub-stepping is on.
I jumped into the source code of the AddForce call and noticed that it really just calls the FBodyINstance’s implementation of AddForce and that it has hard coded the bAllowSubstepping parameter to true. I’m not sure if this is relevant.
I realize I could test this but I’m afraid I may just get a false negative.
-
Does anyone have a good way to test the consistency of my simulation when given the same player inputs? I want to test consistency across sessions where the frame-rate is stable (at 60 fps) and consistency between sessions where the framerate is low. By taking focus off of the editor I can drop the framerate to around 3 fps and things appear to behave correctly but then I can’t test with player inputs.
-
What issues might I run into with accurately replicating racers if I decide to add networked multiplayer?
-
I have had some weird reactions to collisions where it seems to launch my racer away from the collided object. I have double-checked that it is not due to any of the forces I am adding (I cap the magnitude of each force immediately before it is applied). At first I thought it might just be a current known/unfixed bug with landscape(I’ll try to find the link to the post that made me think this but it was dated 2014). I’m not so sure now though since I have, less frequently, encountered this when colliding with static meshes.
This is the mesh that I am testing with and its collision box:
Collision settings:
Physics settings:

Project physics settings:

I am using a physics material with friction set to 0 and reciprocity set to 0.
Please let me know if there is any more information I can provide.
Help with any of these questions and concerns would be greatly appreciated. In the meantime I will continue to try and answer my own questions and update this post with any discoveries.