Jump to content

Gravity with Low Frame rate reacts differently


Recommended Posts

So I've been working on a game (First Person Shooter):

One of the problems I have now is with the gravity.
In stead of having people look through the mess of the code for that project, I've simplified it here:

That scene might take a minute to load. 
It creates 3,000 random spheres in the scene.

You can make the camera jump by clicking the mouse.

The problem is this.
When the scene gets complicated, and the frame rate drops, gravity slows down.
So, in this example scene with the 3,000 spheres I get 60fps in chrome on my desktop.

When I jump, it lasts less then a second with my current settings.
But, on my laptop (or in a browser that renders slower - example: Firefox)
were I get 20fps in that scene, the jump lasts about 4 seconds.


This becomes a real problem in my game because on slower machines you can fly across the board with one jump,

If I change the settings and adjust them for slower computers, then on faster computers the jump time is to short.


Is there a better way of doing this?

Thanks for any help.

Link to comment
Share on other sites



Thanks for the advise.  I haven't really learned how to use Octree yet.  I've read about it, and I think I understand the basic concept, but I haven't used it in code yet.

I know Octree can be use for collision detection,

but I'm guessing it can improve performance in other ways

since in this since the only collisions would be between the camera and the ground.

The line you gave :

if(scene._activeMeshes.length > 100) scene.createOrUpdateSelectionOctree();

I'm guessing that that checks if there are more then 100 meshes visible to the camera and if so use Octree.

I'm assuming this has to be checked regularly, so do I put it in the render loop?
If so I just tried that and it made no difference.
If it goes somewhere else, or only needs to be called once, please let me know.

Although it seems like Octree is important and something I need to learn to improve performance of my project,

I also feel like even if this did help, it would be more of a work around then a fix.
Because, even if I improve performance, there will still be times where the game might still run slow, and if it does, it shouldn't effect the game like this.

Is there any way to make gravity work on a time base rather then a render rate?
I'm sure I could hack something together, I'm just hoping that there is already something that I can use rather then create something.

In my head, the way I would do it would be based on a time interval and it would move the camera down a certain amount based on time.

So, if anyone knows of a way that this is already done, please let me know.

Other wise I might start working on throwing something together myself.
Which will probably be ugly and I will spend forever tweaking it :D

Link to comment
Share on other sites

IMO all movement should be distance over time (which oddly enough is the definition of speed...). Currently I don't think that it compensates the distance based on FPS. I remember reading about how to do it in one of my game gems or gpu gems books... I remember that there was a formula for calculating movement by frame, based on FPS, in order to ensure that proper distances and timing were adhered to and in sync.


Google's not helping my find it though today...

Link to comment
Share on other sites

  • 2 years later...
On 6/21/2014 at 0:43 AM, Deltakosh said:

Babylon.js give you a scaled value to autmatically fit your animations/values:


So in your case you can scale your jump value by this value. scene.getAnimationRatio() will be greater when FPS is low to compensate

@Deltakosh this post is two years later extremely helpful! This should be mentioned in the documentation! Maybe here: https://doc.babylonjs.com/tutorials/Cameras

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...