question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

understanding delta in Engine.update

See original GitHub issue

While attempting to simulate a box dropping over 5 seconds, I tried to use different time granularity by varying the “delta” argument to the update function. The code is as follows:

function simulate_no_render(delta) {
  // create world
  var boxA = Bodies.rectangle(400, 0, 80, 80);                             
  World.add(engine.world, [boxA]);        
  var total_time = 5000
  var num_step = total_time / delta     
  for (var i = 0; i < num_step; i++ ) {
    Engine.update(engine, delta)
  }
  console.log(engine.world.bodies[0].position)              
}   

I then called this function with different deltas, 2, 5, 10, and 20. Here are the results:

  Object {x: 400, y: 960.4000000004701}
  Object {x: 400, y: 2252.5106848838022}
  Object {x: 400, y: 4016.504778211938}
  Object {x: 400, y: 6360.991724002313}

I am sure I missed something, because the y position should be similar as it’s the same setting of a box being dropped over 5 seconds, the different delta should introduce some small error, i.e. bigger values of delta would cause a bigger error due to inaccuracies, but it shouldn’t be this drastic. Any clarification would be great!

If this difference is indeed caused by the different delta values, what is the delta used in Runner.run?

After reading the docs it seems the default delta value is 1000 / 60.

And it seems that changing the delta value actually changes the physics of the world, i.e. the simulation is dependent on the delta value, in that both the force and velocity are measured in units time that is the delta: a setVelocity of 10 in a delta of 10ms is twice as fast as a setVelocity of 10 in a delta of 20ms

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
liabrucommented, Sep 2, 2019

I’ve been working on this!

See my pull request #777 which should hopefully resolve these issues around timing and frame-rates. Those interested, if you have any time it would be great if you could experiment with that update in your code and report any issues or success, thanks.

0reactions
sundayzcommented, Feb 2, 2019

I’m trying to run the simulation slower than 16ms, but a bigger delta time makes the objects move slower. When using correction in the world update (calculated as delta / lastDelta) things move MUCH faster than they should. This happens on an object with friction set to zero.

Read more comments on GitHub >

github_iconTop Results From Across the Web

About delta updates
A delta update produces a full baseline index, similar to the baseline update, but does so by joining a smaller extraction of source...
Read more >
Understanding 'delta' :: Godot 4 Recipes - KidsCanCode
This is a floating point value representing the length of time since the previous frame. Typically, this will be approximately 1/60 or 0.0167...
Read more >
Understanding Delta Time - Drew Coleman - Medium
Delta time, or also referred to as elapsed time is usually a value that is calculated for us within modern game engines such...
Read more >
WTF Is? Delta Time in Unreal Engine 4 - YouTube
What is the Delta Time in Unreal Engine 4 .Source Files: https://github.com/MWadstein/wtf-hdi-files.
Read more >
What is Delta Lake? | Databricks on AWS
Updating and modifying Delta Lake tables; Incremental and streaming workloads on Delta Lake; Querying previous versions of a table; Delta Lake ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found