mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-20 17:10:11 -05:00
revert Body.applyForce
This commit is contained in:
parent
f8b64b673e
commit
f7da96413b
3 changed files with 12 additions and 9 deletions
|
@ -108,15 +108,17 @@ Example.events = function() {
|
|||
Composite.add(world, stack);
|
||||
|
||||
var shakeScene = function(engine) {
|
||||
var timeScale = (1000 / 60) / engine.timing.lastDelta;
|
||||
var bodies = Composite.allBodies(engine.world);
|
||||
|
||||
for (var i = 0; i < bodies.length; i++) {
|
||||
var body = bodies[i];
|
||||
|
||||
if (!body.isStatic && body.position.y >= 500) {
|
||||
// Scale force accounting for mass
|
||||
var forceMagnitude = (0.03 * body.mass);
|
||||
// scale force for mass and time applied
|
||||
var forceMagnitude = (0.03 * body.mass) * timeScale;
|
||||
|
||||
// apply the force over a single update
|
||||
Body.applyForce(body, body.position, {
|
||||
x: (forceMagnitude + Common.random() * forceMagnitude) * Common.choose([1, -1]),
|
||||
y: -forceMagnitude + Common.random() * -forceMagnitude
|
||||
|
|
|
@ -42,16 +42,18 @@ Example.timescale = function() {
|
|||
Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
|
||||
]);
|
||||
|
||||
var explosion = function(engine) {
|
||||
var explosion = function(engine, delta) {
|
||||
var timeScale = (1000 / 60) / delta;
|
||||
var bodies = Composite.allBodies(engine.world);
|
||||
|
||||
for (var i = 0; i < bodies.length; i++) {
|
||||
var body = bodies[i];
|
||||
|
||||
if (!body.isStatic && body.position.y >= 500) {
|
||||
// Scale force accounting for mass
|
||||
var forceMagnitude = (0.05 * body.mass);
|
||||
// scale force for mass and time applied
|
||||
var forceMagnitude = (0.05 * body.mass) * timeScale;
|
||||
|
||||
// apply the force over a single update
|
||||
Body.applyForce(body, body.position, {
|
||||
x: (forceMagnitude + Common.random() * forceMagnitude) * Common.choose([1, -1]),
|
||||
y: -forceMagnitude + Common.random() * -forceMagnitude
|
||||
|
@ -153,4 +155,4 @@ Example.timescale.for = '>=0.14.2';
|
|||
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = Example.timescale;
|
||||
}
|
||||
}
|
|
@ -813,10 +813,9 @@ var Axes = require('../geometry/Axes');
|
|||
* @param {vector} force
|
||||
*/
|
||||
Body.applyForce = function(body, position, force) {
|
||||
var timeScale = body.deltaTime / Body._baseDelta;
|
||||
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.force.x += force.x;
|
||||
body.force.y += force.y;
|
||||
body.torque += offset.x * force.y - offset.y * force.x;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue