mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
change Body.applyForce for timing, add initial body.deltaTime
This commit is contained in:
parent
6f5af774ce
commit
3117dfdaa7
3 changed files with 6 additions and 5 deletions
|
@ -117,7 +117,7 @@ Example.events = function() {
|
|||
|
||||
if (!body.isStatic && body.position.y >= 500) {
|
||||
// Scale force accounting for time delta.
|
||||
var forceMagnitude = (0.0005 * body.mass) / (timeScale || 1);
|
||||
var forceMagnitude = (0.03 * body.mass);
|
||||
|
||||
Body.applyForce(body, body.position, {
|
||||
x: (forceMagnitude + Common.random() * forceMagnitude) * Common.choose([1, -1]),
|
||||
|
|
|
@ -52,7 +52,7 @@ Example.timescale = function() {
|
|||
|
||||
if (!body.isStatic && body.position.y >= 500) {
|
||||
// Scale force accounting for time delta.
|
||||
var forceMagnitude = (0.001 * body.mass) / (timeScale || 1);
|
||||
var forceMagnitude = (0.05 * body.mass);
|
||||
|
||||
Body.applyForce(body, body.position, {
|
||||
x: (forceMagnitude + Common.random() * forceMagnitude) * Common.choose([1, -1]),
|
||||
|
|
|
@ -94,7 +94,7 @@ var Axes = require('../geometry/Axes');
|
|||
area: 0,
|
||||
mass: 0,
|
||||
inertia: 0,
|
||||
deltaTime: null,
|
||||
deltaTime: Common._timeUnit,
|
||||
_original: null
|
||||
};
|
||||
|
||||
|
@ -778,8 +778,9 @@ var Axes = require('../geometry/Axes');
|
|||
* @param {vector} force
|
||||
*/
|
||||
Body.applyForce = function(body, position, force) {
|
||||
body.force.x += force.x;
|
||||
body.force.y += force.y;
|
||||
var timeScale = body.deltaTime / Common._timeUnit;
|
||||
body.force.x += force.x / timeScale;
|
||||
body.force.y += force.y / timeScale;
|
||||
var offset = { x: position.x - body.position.x, y: position.y - body.position.y };
|
||||
body.torque += offset.x * force.y - offset.y * force.x;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue