How to test frame rate dependency in my code?

Hi all!
I was wondering, what is the right way to understand if my code is frame rate dependent?

I tried to open a new project from the platformer game template.
I made this 3 tests:

  1. Frame Cap = 0; V-Sync enabled (normal setup):
    frameCap0-YesVSync
    This is the normal and default setup. (my screen refresh rate is 60Hz)

  2. Frame Cap = 10; V-Sync disabled (slow frame rate):
    frameCap10-NoVSync
    In the test 2, the game seem to preserve its original speed (in term of character moving and jump). But as you can see, it appears that physics timestep seem to be linked to the frame rate as frequently it fails to detect collisions properly.

  3. Frame Cap = 1000; V-Sync disabled (ultra high frame rate):
    frameCap1000-NoVSync
    In the test 3, the character is moving and jumping/falling like at the half of the original speed. But also the character animation is going slower, so I don’t understand…

(GIFs are at 25 fps)

So what I’m doing wrong here?

It is right to use the frame cap and V-Sync to test frame rate dependency? What actually does the frame cap in detail? In which range it must be used?
How to prevent frame dependency? Is it enough to multiply by dt in all my move operations?
How to deal with frame dependent physics (if it is so?)

Thank you! :slightly_smiling_face:

A way to fix the framerate issues is to use raycast for collisions. I don’t know the code of this project, but likely the code is allowing too big of a jump of movement for the frame time between frames. In this case, dt isn’t enough (though you should use it), you need to use something like a raycast to be sure.

These framerate issues should eventually be fixed so it just works.

For other info, check this thread

1 Like

And the settings explained in the manuals: https://defold.com/manuals/project-settings/#vsync-frame-cap-and-swap-interval

1 Like

Thank you Pkeod!

So we can say that the change of the game execution speed, in this example, are not fault of the code, but is an opened issue on Defold?
And so actually it is not worth testing frame dependency by changing the frame cap right?
And the physics issue can be solved using raycasting.

Did I get it right?

Also thank you @britzl , I missed out this appendix in the documentation page!

The main issue is that there are problems related to the update rate / VSync features which are not always working as you would expect them to and they need to be fixed.

There should still be an ideal setup you can do / when that doesn’t work make sure you ask people to force enable VSync for your game in their graphics card settings. Maybe something like DefOS could get VSync to be forced to be enabled. Maybe there is an easy engine fix. Maybe the underlying issues can be fixed when moving to GLFW3. I’d not expect it to happen in the very near future though so best to try and work around it like using raycasting.

The ideal you want is for the game to run at 60FPS on everyone’s computer without needing to worry about the issues you can sometimes see, which are usually caused by some computers not having VSync enabled for Defold based games (and AFAIK we don’t know why yet).