0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-26 13:49:01 -05:00

derive velocity from position in setters

This commit is contained in:
liabru 2022-01-05 23:13:46 +00:00
parent fe985288d6
commit b6de9ed8c5

View file

@ -549,8 +549,8 @@ var Axes = require('../geometry/Axes');
var timeScale = body.deltaTime / Body.timeUnit;
body.positionPrev.x = body.position.x - velocity.x * timeScale;
body.positionPrev.y = body.position.y - velocity.y * timeScale;
body.velocity.x = velocity.x * timeScale;
body.velocity.y = velocity.y * timeScale;
body.velocity.x = (body.position.x - body.positionPrev.x) / timeScale;
body.velocity.y = (body.position.y - body.positionPrev.y) / timeScale;
body.speed = Vector.magnitude(body.velocity);
};
@ -599,7 +599,7 @@ var Axes = require('../geometry/Axes');
Body.setAngularVelocity = function(body, velocity) {
var timeScale = body.deltaTime / Body.timeUnit;
body.anglePrev = body.angle - velocity * timeScale;
body.angularVelocity = velocity * timeScale;
body.angularVelocity = (body.angle - body.anglePrev) / timeScale;
body.angularSpeed = Math.abs(body.angularVelocity);
};