syed samoon Posted March 29, 2018 Share Posted March 29, 2018 Hi Everyone, How to move a object smoothly with deltaTime? Thank you Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 29, 2018 Share Posted March 29, 2018 Hi Syed, I think we will need a bit more information in order to help Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted March 29, 2018 Share Posted March 29, 2018 what are you doing now? https://playground.babylonjs.com generally.. speed * deltaTime. // Speed without delta, at 60 FPS. var speed = 0.0167; // Aproximately 1 unit per second. // Convert speed value to be used with deltaTime. // Divide by 16.66.. (Ca. deltaTime at 60FPS, we want to keep 1 unit / second) // This should only be done Once. speed /= (1000/60); // Applying the deltaTime // This should be done once each frame. var deltaSpeed = speed * (engine.getDeltaTime()); myMesh.position.x += deltaSpeed; Quote Link to comment Share on other sites More sharing options...
syed samoon Posted March 30, 2018 Author Share Posted March 30, 2018 16 hours ago, RaananW said: Hi Syed, I think we will need a bit more information in order to help Hi @RaananW in my game i got 38 FPS in mobile but still the gameplay was slow. my friend suggest me to use deltaTime so what i'm asking this. in my script var speed = 5; player.position.z += speed; Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted March 30, 2018 Share Posted March 30, 2018 2 hours ago, syed samoon said: var speed = 5; player.position.z += speed; 19 hours ago, aWeirdo said: // Speed without delta, at 60 FPS. var speed = 0.0167; // Aproximately 1 unit per second. // Convert speed value to be used with deltaTime. // Divide by 16.66.. (Ca. deltaTime at 60FPS, we want to keep 1 unit / second) // This should only be done Once. speed /= (1000/60); // Applying the deltaTime // This should be done once each frame. var deltaSpeed = speed * (engine.getDeltaTime()); myMesh.position.x += deltaSpeed; GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
syed samoon Posted April 3, 2018 Author Share Posted April 3, 2018 any buddy have an idea about this?? Quote Link to comment Share on other sites More sharing options...
Guest Posted April 3, 2018 Share Posted April 3, 2018 Sorry but we have not enough info to help Quote Link to comment Share on other sites More sharing options...
Guest Posted April 4, 2018 Share Posted April 4, 2018 Did you read this one: http://doc.babylonjs.com/how_to/optimizing_your_scene It is a good start to think about optimizations Quote Link to comment Share on other sites More sharing options...
syed samoon Posted April 5, 2018 Author Share Posted April 5, 2018 7 hours ago, Deltakosh said: Did you read this one: http://doc.babylonjs.com/how_to/optimizing_your_scene It is a good start to think about optimizations i was optimized with this below script var priority = 0; var options = new BABYLON.SceneOptimizerOptions(_this.frameTarget, 1000); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 1)); options.addCustomOptimization(function () { _this.engine.setHardwareScalingLevel(0.5); return true; }, function () { return "Turning mirror off"; }); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 1.5)); options.addCustomOptimization(function () { _this.engine.setHardwareScalingLevel(1.5); return true; }, function () { return "Turning ground off"; }); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 2)); options.addCustomOptimization(function () { _this.init.engine.setHardwareScalingLevel(2); return true; }, function () { return "Turning ground off"; }); var optimizer = new BABYLON.SceneOptimizer(_this.init.scene, options); optimizer.start(); // Wiring optimizer.onSuccessObservable.add(function () { console.log("optimization success"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); optimizer.onNewOptimizationAppliedObservable.add(function (optim) { console.log("optimizing"); }); optimizer.onFailureObservable.add(function () { console.log("optimization failed"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); Quote Link to comment Share on other sites More sharing options...
syed samoon Posted April 5, 2018 Author Share Posted April 5, 2018 Just now, syed samoon said: i was optimized with this below script var priority = 0; var options = new BABYLON.SceneOptimizerOptions(_this.frameTarget, 1000); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 1)); options.addCustomOptimization(function () { _this.engine.setHardwareScalingLevel(0.5); return true; }, function () { return "Turning mirror off"; }); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 1.5)); options.addCustomOptimization(function () { _this.engine.setHardwareScalingLevel(1.5); return true; }, function () { return "Turning ground off"; }); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 2)); options.addCustomOptimization(function () { _this.init.engine.setHardwareScalingLevel(2); return true; }, function () { return "Turning ground off"; }); var optimizer = new BABYLON.SceneOptimizer(_this.init.scene, options); optimizer.start(); // Wiring optimizer.onSuccessObservable.add(function () { console.log("optimization success"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); optimizer.onNewOptimizationAppliedObservable.add(function (optim) { console.log("optimizing"); }); optimizer.onFailureObservable.add(function () { console.log("optimization failed"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); is there anything wrong in this optimization Quote Link to comment Share on other sites More sharing options...
Guest Posted April 5, 2018 Share Posted April 5, 2018 this looks wrong to me you are doing twice every check (why adding custom otpimization when you are already using HardwareScalingOptimization ? You should read this: http://doc.babylonjs.com/how_to/how_to_use_sceneoptimizer Quote Link to comment Share on other sites More sharing options...
syed samoon Posted April 10, 2018 Author Share Posted April 10, 2018 var options = new BABYLON.SceneOptimizerOptions(_this.init.frameTarget, 1000); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 1)); options.addOptimization(new BABYLON.TextureOptimization(2, 1024)); _this.init.engine.setHardwareScalingLevel(1); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 1.5)); options.addOptimization(new BABYLON.TextureOptimization(2, 512)); _this.init.engine.setHardwareScalingLevel(1.5); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 2)); options.addOptimization(new BABYLON.TextureOptimization(2, 256)); _this.init.engine.setHardwareScalingLevel(2); var optimizer = new BABYLON.SceneOptimizer(_this.init.scene, options); optimizer.start(); // Wiring optimizer.onSuccessObservable.add(function () { console.log("optimization success"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); optimizer.onNewOptimizationAppliedObservable.add(function (optim) { console.log("optimizing"); }); optimizer.onFailureObservable.add(function () { console.log("optimization failed"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); _this.init.optimized = true; Quote Link to comment Share on other sites More sharing options...
syed samoon Posted April 10, 2018 Author Share Posted April 10, 2018 is this right... Quote Link to comment Share on other sites More sharing options...
syed samoon Posted April 24, 2018 Author Share Posted April 24, 2018 Hi Everyone, Can you help me.. if anyone have model script for optimizing the scene. https://www.babylonjs-playground.com/#3Q8PCL i can't understand this. Quote Link to comment Share on other sites More sharing options...
syed samoon Posted April 24, 2018 Author Share Posted April 24, 2018 var priority = 0; var options = new BABYLON.SceneOptimizerOptions(_this.init.frameTarget, 1000); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 1)); options.addOptimization(new BABYLON.TextureOptimization(2, 1024)); options.addOptimization(new BABYLON.RenderTargetsOptimization(1)); options.addOptimization(new BABYLON.PostProcessesOptimization(1)); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 2)); options.addOptimization(new BABYLON.TextureOptimization(2, 512)); options.addOptimization(new BABYLON.RenderTargetsOptimization(2)); options.addOptimization(new BABYLON.PostProcessesOptimization(2)); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 3)); options.addOptimization(new BABYLON.TextureOptimization(2, 256)); options.addOptimization(new BABYLON.RenderTargetsOptimization(3)); options.addOptimization(new BABYLON.PostProcessesOptimization(3)); var optimizer = new BABYLON.SceneOptimizer(_this.init.scene, options); optimizer.start(); // Wiring optimizer.onSuccessObservable.add(function () { console.log("optimization success"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); optimizer.onNewOptimizationAppliedObservable.add(function (optim) { console.log("optimizing"); }); optimizer.onFailureObservable.add(function () { console.log("optimization failed"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); Quote Link to comment Share on other sites More sharing options...
syed samoon Posted April 24, 2018 Author Share Posted April 24, 2018 6 minutes ago, syed samoon said: var priority = 0; var options = new BABYLON.SceneOptimizerOptions(_this.init.frameTarget, 1000); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 1)); options.addOptimization(new BABYLON.TextureOptimization(2, 1024)); options.addOptimization(new BABYLON.RenderTargetsOptimization(1)); options.addOptimization(new BABYLON.PostProcessesOptimization(1)); _this.init.engine.setHardwareScalingLevel(1); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 2)); options.addOptimization(new BABYLON.TextureOptimization(2, 512)); options.addOptimization(new BABYLON.RenderTargetsOptimization(2)); options.addOptimization(new BABYLON.PostProcessesOptimization(2)); _this.init.engine.setHardwareScalingLevel(1.5); options.addOptimization(new BABYLON.HardwareScalingOptimization(0, 3)); options.addOptimization(new BABYLON.TextureOptimization(2, 256)); options.addOptimization(new BABYLON.RenderTargetsOptimization(3)); options.addOptimization(new BABYLON.PostProcessesOptimization(3)); _this.init.engine.setHardwareScalingLevel(2); var optimizer = new BABYLON.SceneOptimizer(_this.init.scene, options); optimizer.start(); // Wiring optimizer.onSuccessObservable.add(function () { console.log("optimization success"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); optimizer.onNewOptimizationAppliedObservable.add(function (optim) { console.log("optimizing"); }); optimizer.onFailureObservable.add(function () { console.log("optimization failed"); _this.init.loadingProgress = 100; _this.init.engine.loadingUIText = Math.floor(_this.init.loadingProgress) + " %"; _this.init.engine.hideLoadingUI(); }); is this right?? Quote Link to comment Share on other sites More sharing options...
syed samoon Posted April 30, 2018 Author Share Posted April 30, 2018 anybody else to help me Quote Link to comment Share on other sites More sharing options...
Guest Posted April 30, 2018 Share Posted April 30, 2018 It could be so much easier to help you if you could provide a PG Quote Link to comment Share on other sites More sharing options...
syed samoon Posted May 2, 2018 Author Share Posted May 2, 2018 On 4/30/2018 at 8:46 PM, Deltakosh said: It could be so much easier to help you if you could provide a PG sorry i don't know how to create a PG Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 2, 2018 Share Posted May 2, 2018 49 minutes ago, syed samoon said: sorry i don't know how to create a PG PG = playground http://doc.babylonjs.com/babylon101/first http://doc.babylonjs.com/features/playground Quote Link to comment Share on other sites More sharing options...
max123 Posted May 2, 2018 Share Posted May 2, 2018 I presume @syed samoon is talking about game loop delta timing. Generally speaking, game loops, in their simplest form, work similar to: const _fps = 60.0; const _interval = 1000.0 / _fps; const _lastTick = performance.now(); private tick() { let now = performance.now(); requestAnimationFrame(tick); let frameTime = now - _lastTick; _lastTick = now; update(frameTime); } Where frametime/deltatime is the time spent within one tick. You can go all fancy and and split update/render methods and run update() inside a while loop : _delta += frameTime; while (_delta >= _interval) { _delta -= _interval; update(1); } Which will give you constant update (could be important for game state/physics) and render-whenever-you-can setup. But as other users have pointed out, you can use Babylon's engine.getDeltaTime() 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.