0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

update Example.staticFriction and Example.timeScale

This commit is contained in:
liabru 2022-01-01 19:42:30 +00:00
parent 5ddac71316
commit 11d5e73c1f
2 changed files with 8 additions and 4 deletions

View file

@ -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);
});

View file

@ -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, {
@ -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;