{"action":"created","issue":{"url":"https://api.github.com/repos/liabru/matter-js/issues/148","repository_url":"https://api.github.com/repos/liabru/matter-js","labels_url":"https://api.github.com/repos/liabru/matter-js/issues/148/labels{/name}","comments_url":"https://api.github.com/repos/liabru/matter-js/issues/148/comments","events_url":"https://api.github.com/repos/liabru/matter-js/issues/148/events","html_url":"https://github.com/liabru/matter-js/issues/148","id":104590365,"number":148,"title":"understanding delta in Engine.update","user":{"login":"evanthebouncy","id":1041553,"avatar_url":"https://avatars.githubusercontent.com/u/1041553?v=3","gravatar_id":"","url":"https://api.github.com/users/evanthebouncy","html_url":"https://github.com/evanthebouncy","followers_url":"https://api.github.com/users/evanthebouncy/followers","following_url":"https://api.github.com/users/evanthebouncy/following{/other_user}","gists_url":"https://api.github.com/users/evanthebouncy/gists{/gist_id}","starred_url":"https://api.github.com/users/evanthebouncy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evanthebouncy/subscriptions","organizations_url":"https://api.github.com/users/evanthebouncy/orgs","repos_url":"https://api.github.com/users/evanthebouncy/repos","events_url":"https://api.github.com/users/evanthebouncy/events{/privacy}","received_events_url":"https://api.github.com/users/evanthebouncy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/liabru/matter-js/labels/investigate","name":"investigate","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2015-09-02T23:13:19Z","updated_at":"2016-07-04T09:31:51Z","closed_at":null,"body":"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. \r\nThe code is as follows:\r\n\r\n    function simulate_no_render(delta) {\r\n      // create world\r\n      var boxA = Bodies.rectangle(400, 0, 80, 80);                             \r\n      World.add(engine.world, [boxA]);        \r\n      var total_time = 5000\r\n      var num_step = total_time / delta     \r\n      for (var i = 0; i < num_step; i++ ) {\r\n        Engine.update(engine, delta)\r\n      }\r\n      console.log(engine.world.bodies[0].position)              \r\n    }   \r\n\r\nI then called this function with different deltas, 2, 5, 10, and 20. Here are the results:\r\n\r\n      Object {x: 400, y: 960.4000000004701}\r\n      Object {x: 400, y: 2252.5106848838022}\r\n      Object {x: 400, y: 4016.504778211938}\r\n      Object {x: 400, y: 6360.991724002313}\r\n\r\nI 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!\r\n\r\nIf this difference is indeed caused by the different delta values, what is the delta used in Runner.run?\r\n\r\nAfter reading the docs it seems the default delta value is 1000 / 60. \r\n\r\nAnd 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 "},"comment":{"url":"https://api.github.com/repos/liabru/matter-js/issues/comments/230247682","html_url":"https://github.com/liabru/matter-js/issues/148#issuecomment-230247682","issue_url":"https://api.github.com/repos/liabru/matter-js/issues/148","id":230247682,"user":{"login":"liabru","id":654420,"avatar_url":"https://avatars.githubusercontent.com/u/654420?v=3","gravatar_id":"","url":"https://api.github.com/users/liabru","html_url":"https://github.com/liabru","followers_url":"https://api.github.com/users/liabru/followers","following_url":"https://api.github.com/users/liabru/following{/other_user}","gists_url":"https://api.github.com/users/liabru/gists{/gist_id}","starred_url":"https://api.github.com/users/liabru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liabru/subscriptions","organizations_url":"https://api.github.com/users/liabru/orgs","repos_url":"https://api.github.com/users/liabru/repos","events_url":"https://api.github.com/users/liabru/events{/privacy}","received_events_url":"https://api.github.com/users/liabru/received_events","type":"User","site_admin":false},"created_at":"2016-07-04T09:31:51Z","updated_at":"2016-07-04T09:31:51Z","body":"Well like I said, the TCV falls back to regular Verlet when there is no change in timestep ('correction'):\r\nFrom the [article](http://lonesock.net/article/verlet.html):\r\n\r\nOriginal Verlet:\r\nxi+1 = xi + (xi - xi-1) + a * dt * dt\r\n\r\nTime-Corrected Verlet:\r\nxi+1 = xi + (xi - xi-1) * __(dti / dti-1)__ + a * dti * dti\r\n\r\nThe term in bold is what I refer to as `correction` in the engine. When using `Matter.Runner` at full 60fps then that term is `(dti / dti-1) === 16.666 / 16.666 === 1`. If you're updating with your own runner and don't pass a value for `correction` then it is also `1`.\r\n\r\nWhile TCV may still be flawed, I don't think it's the source of the problem you're seeing.\r\n\r\nThe major difference in the engine is the extra air friction term, which is a factor of velocity. I hoped this would remain constant with regards to timestep, but will need to check."}}
{"actor":{"display_login":"liabru"}}