Different speed of work depending on the hertz of the monitor

I ran into a problem that the game runs faster at 144 fps.
Then I decided to use deltaTime (scene.getAnimationRatio()).
But then I ran into an issue that if I switch to another tab, then upon returning to the tab, the box jerks sharply. https://playground.babylonjs.com/#WLJB8F#1
Having fixed this issue, I returned to the first one again, that the game starts to work faster at different hertz. - https://playground.babylonjs.com/#WLJB8F#2
Is there any way to solve these problems at the same time?

By default, the engine’s render speed follows the fps of the graphics
so. If what you want is to control the speed of a specific mesh, such as a PG, rather than the overall render speed of 60 FPS, you can do the following PG

2 Likes

Thank you very much for the answer.
Now it works well, but if the performance drops (on the phone) and the fps drops below 60, then the game still runs slower than it should be. Maybe there is some alternative?

1 Like

The method shown is for setting the frame, and the dropped frame on mobile is something that needs to be optimized differently from this method.

There are a number of ways to do this, including a full optimization like the article below, and the

Or you can change the overall level design to be lower on mobile.
You can also create logic to catch frames during rendering and change the degree of implementation.
The way I typically use this is to set a median value for the level on an all-inclusive basis, so that frames are closer to 50 on medium mobile, with additional limits for low and high so that the user can choose.

1 Like

A good general practice is to keep static values that you then multiply by the DeltaTime,
DeltaTime is automaticly calculated by the engine; Roughly equals 1000/FPS

// 1 unit divided by 1000ms
// Expected speed is 1 unit per second.
const speed = 1 / 1000;

// inside renderloop

const actualSpeed = speed * engine.getDeltaTime(); 
// actualSpeed is now 1 unit per IRL second independent of the client's FPS

Edit:
Regarding tabbing issue, you can do something like,
If deltatime > (avg deltatime of last 10 frames * 5)
Use avg deltatime for that frame.
Or simular.

1 Like