Skip to content

Commit

Permalink
update Example.staticFriction and Example.timeScale
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jan 1, 2022
1 parent 5ddac71 commit 11d5e73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions examples/staticFriction.js
Expand Up @@ -62,6 +62,11 @@ Example.staticFriction = function() {

var px = 400 + 100 * Math.sin((engine.timing.timestamp - 1500) * 0.001);

// manual update velocity required for older releases
if (Matter.version === '0.18.0') {
Body.setVelocity(body, { x: px - body.position.x, y: 0 });
}

Body.setPosition(body, { x: px, y: body.position.y }, true);
});

Expand Down
7 changes: 3 additions & 4 deletions examples/timescale.js
Expand Up @@ -42,15 +42,14 @@ Example.timescale = function() {
Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
]);

var explosion = function(engine, delta) {
var timeScale = delta / 1000;
var explosion = function(engine) {
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 time delta.
// Scale force accounting for mass
var forceMagnitude = (0.05 * body.mass);

Body.applyForce(body, body.position, {
Expand All @@ -65,7 +64,7 @@ Example.timescale = function() {
lastTime = Common.now();

Events.on(engine, 'afterUpdate', function(event) {
var timeScale = timeScale = (event.delta || (1000 / 60)) / 1000;
var timeScale = (event.delta || (1000 / 60)) / 1000;

// tween the timescale for bullet time slow-mo
engine.timing.timeScale += (timeScaleTarget - engine.timing.timeScale) * 12 * timeScale;
Expand Down

0 comments on commit 11d5e73

Please sign in to comment.