Run game and physics faster

Hi,

I’m trying to make a 2D game simulation in order to utilise it for automated tests.
I’ve managed to make the game run on it’s own and simulate players behaviour.
However this runs at normal game pace, which is too slow for any meaningful amount of tests.

I want to speed up the game simulation, while keeping all the calculations (especially physics) precise.
That includes but is not limited to:

  • consistent impact of two objects colliding (regardless of simulation pace)
  • consistent movement trajectory (regardless of simulation pace)
  • consistent relative velocity and motion of all entities

What I tried:

  1. Increase Physics Ticks Per Second: this doesn’t speed up simulation, it only increases the number of motion equation samples
  2. Increase Max Physics Ticks Per Frame: this doesn’t speed up simulation but increases the number of samples
  3. Disable V-Sync, disable rendering, set unlimited FPS, disable low processor optimisation. This makes the game run faster but it has no effect on physics. Since all motion equation is tied to physics processing this solution does not work
  4. Increase time scale. This speeds up everything, including physics simulation, however it introduces many problems, such as: physics becomes inaccurate (way less samples due to delta becoming a bigger value), magnitude of physical properties (such as velocity) also increases, which obviously leads to a whole lot of other problems (like collision impact strength)

So far I have not found a way to make the game run exactly the same as it would run in a normal way but at a much faster pace. Basically, what I want to achieve is the same effect you get when playing video at X2 speed. I don’t need any rendering or network features, I don’t need to wait for CPU and GPU to sync.

Reread this and tell me it makes sense, because it doesn’t to me.

Also, I’ll admit I’m not into that kind of simulation, but if you want to simulate player behavior, making things 2x faster would defeat the purpose of simulation normal player behavior because players don’t play at 2x the speed. :man_shrugging:

It does in a sense that I don’t need any rendering enabled, which can make CPU wait for GPU to finish

Gotcha.

I haven’t checked the internals of the engine deep enough to check if/how much of anything is run CPU/GPU-side. But, it’s possible some of the non-visual code could be run on the GPU. I don’t know if that could break the simulation, so you should account for that or wait until someone with more knowledge than me tell you if it’s the case.

I have actually just found the solution:

  1. Use Engine.time_scale to set simulation speed
  2. In order not to loose any accuracy in physic calculations, multiply Engine.physics_ticks_per_second by the Engine.time_scale

So, say, my simulation runs at 10X speed. This means I need to make 10 times more samples in order to not loose any accuracy in physics

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.