Metalx1000 Posted June 20, 2014 Share Posted June 20, 2014 So I've been working on a game (First Person Shooter):http://filmsbykris.com/scripts/metal_bulletsOne 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:http://tinyurl.com/pfgjthpThat 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. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 20, 2014 Share Posted June 20, 2014 Try using Octree to optimize the scene :if(scene._activeMeshes.length > 100) scene.createOrUpdateSelectionOctree();This should increase your fps. Quote Link to comment Share on other sites More sharing options...
Metalx1000 Posted June 20, 2014 Author Share Posted June 20, 2014 dad72, 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 wayssince 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 Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 20, 2014 Share Posted June 20, 2014 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... Quote Link to comment Share on other sites More sharing options...
Metalx1000 Posted June 20, 2014 Author Share Posted June 20, 2014 reddozen, You are correct, distance over time. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 20, 2014 Share Posted June 20, 2014 Babylon.js give you a scaled value to autmatically fit your animations/values:scene.getAnimationRatio()So in your case you can scale your jump value by this value. scene.getAnimationRatio() will be greater when FPS is low to compensate smatt 1 Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 20, 2014 Share Posted June 20, 2014 awesome Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 20, 2014 Share Posted June 20, 2014 Good to know, I would have learned something with getAnimationRatio() Quote Link to comment Share on other sites More sharing options...
smatt Posted August 4, 2016 Share Posted August 4, 2016 On 6/21/2014 at 0:43 AM, Deltakosh said: Babylon.js give you a scaled value to autmatically fit your animations/values: scene.getAnimationRatio() 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 4, 2016 Share Posted August 4, 2016 No problem feel free to update the doc Quote Link to comment Share on other sites More sharing options...
smatt Posted August 5, 2016 Share Posted August 5, 2016 For those who get here because they are having problems with different camera speeds on low-end devices: BABYLON.FreeCamera.prototype._computeLocalCameraSpeed = function() { return this.speed * scene.getAnimationRatio(); }; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.