Please find a link here to a playground: https://www.babylonjs-playground.com/#3EDS3A#22
Please click inside the scene to activate pointer lock and use the WASD keys to move and the SPACE key to jump.
In Chrome, with 60 FPS, the character can only jump a short height:
In Brave, with ~300 FPS (using
--disable-frame-rate-limit), the character can jump over the top of the red slide:
Note: The GIF’s above show lower FPS than mentioned, since the recording software decreases FPS.
Could someone please shed light on why a higher framerate allows the character to jump higher?
move() is called every frame in
scene.registerBeforeRender(). Inside the function
move(), the delta time between both frames is considered:
const delta = command.frameTime - prevFrameTime;
Whenever the player jumps, their vertical velocity is suddenly increased to
velocity.y = 0.15. And every frame, the vertical velocity is decreased by
delta / 3000 to simulate gravity, which takes into account the delta time between both frames.
Since we are accounting for the delta time, I’m unsure why the jump height depends on the framerate.
Thank you all for your help!