I got an question about how to make Physics computations independant of the framerate of the game.
I have one actor, a bouncing ball that have an impulse apply to it every tick to compensate the gravity. And when close to the ground, it receive a big impulse to make it “bounce”.
But the catch is that the final result will be very different depending of the framerate :
As we can see in these 3 gifs, in the first case with no restriction on the FPS, the ball is perfectly bouncing and slowly falling.
In the second where I limit the max fps to 30, sometimes we only have half of a bounce. And for the third with a limit at 10, we only have small bounces and the ball could stay on the ground for a time.
( I know that there is also a way to register every ticks the substep’s method on the body instance of my StaticMesh, but this way from the BeginPlay seems more ideal and I didn’t see any differences. )
So, from that I would thought that every thing should have been identical no matter what the number of FPS were. I don’t think I forgot to enable something on the project settings either :
You will noticed that I don’t multiply the impulse with the delta time on the “counter gravity”. I don’t understand why but it seems that we don’t have to use the delta time in our physics tick computations.
I have tried with both anyway, and it didn’t change anything.
I displayed the DeltaTime that I have on the screen to see if it was indepedant of the framerate.
When I set the limit to 30FPS, my DeltaTime is always 0.033333, and when sets to 10FPS it’s 0.1000. Which is exactly the inverse of the number of FPS, which proves that the substepping system is not working at all. And I don’t understand why =/
I code in c++ but it would be the same if I had made it available to BP.
Another tried that I made is to create a counter of substepping.
In my Substepping tick I add +1 to my counter and on actor tick I display this counter and reset it.
It always display 1 :