0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-30 10:20:52 -05:00

change Body.applyForce for timing, add initial body.deltaTime

This commit is contained in:
liabru 2020-03-11 23:50:41 +00:00
parent 6f5af774ce
commit 3117dfdaa7
3 changed files with 6 additions and 5 deletions

View file

@ -117,7 +117,7 @@ Example.events = function() {
if (!body.isStatic && body.position.y >= 500) { if (!body.isStatic && body.position.y >= 500) {
// Scale force accounting for time delta. // 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, { Body.applyForce(body, body.position, {
x: (forceMagnitude + Common.random() * forceMagnitude) * Common.choose([1, -1]), x: (forceMagnitude + Common.random() * forceMagnitude) * Common.choose([1, -1]),

View file

@ -52,7 +52,7 @@ Example.timescale = function() {
if (!body.isStatic && body.position.y >= 500) { if (!body.isStatic && body.position.y >= 500) {
// Scale force accounting for time delta. // 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, { Body.applyForce(body, body.position, {
x: (forceMagnitude + Common.random() * forceMagnitude) * Common.choose([1, -1]), x: (forceMagnitude + Common.random() * forceMagnitude) * Common.choose([1, -1]),

View file

@ -94,7 +94,7 @@ var Axes = require('../geometry/Axes');
area: 0, area: 0,
mass: 0, mass: 0,
inertia: 0, inertia: 0,
deltaTime: null, deltaTime: Common._timeUnit,
_original: null _original: null
}; };
@ -778,8 +778,9 @@ var Axes = require('../geometry/Axes');
* @param {vector} force * @param {vector} force
*/ */
Body.applyForce = function(body, position, force) { Body.applyForce = function(body, position, force) {
body.force.x += force.x; var timeScale = body.deltaTime / Common._timeUnit;
body.force.y += force.y; 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 }; var offset = { x: position.x - body.position.x, y: position.y - body.position.y };
body.torque += offset.x * force.y - offset.y * force.x; body.torque += offset.x * force.y - offset.y * force.x;
}; };