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:
parent
fe985288d6
commit
b6de9ed8c5
1 changed files with 3 additions and 3 deletions
|
@ -549,8 +549,8 @@ var Axes = require('../geometry/Axes');
|
||||||
var timeScale = body.deltaTime / Body.timeUnit;
|
var timeScale = body.deltaTime / Body.timeUnit;
|
||||||
body.positionPrev.x = body.position.x - velocity.x * timeScale;
|
body.positionPrev.x = body.position.x - velocity.x * timeScale;
|
||||||
body.positionPrev.y = body.position.y - velocity.y * timeScale;
|
body.positionPrev.y = body.position.y - velocity.y * timeScale;
|
||||||
body.velocity.x = velocity.x * timeScale;
|
body.velocity.x = (body.position.x - body.positionPrev.x) / timeScale;
|
||||||
body.velocity.y = velocity.y * timeScale;
|
body.velocity.y = (body.position.y - body.positionPrev.y) / timeScale;
|
||||||
body.speed = Vector.magnitude(body.velocity);
|
body.speed = Vector.magnitude(body.velocity);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -599,7 +599,7 @@ var Axes = require('../geometry/Axes');
|
||||||
Body.setAngularVelocity = function(body, velocity) {
|
Body.setAngularVelocity = function(body, velocity) {
|
||||||
var timeScale = body.deltaTime / Body.timeUnit;
|
var timeScale = body.deltaTime / Body.timeUnit;
|
||||||
body.anglePrev = body.angle - velocity * timeScale;
|
body.anglePrev = body.angle - velocity * timeScale;
|
||||||
body.angularVelocity = velocity * timeScale;
|
body.angularVelocity = (body.angle - body.anglePrev) / timeScale;
|
||||||
body.angularSpeed = Math.abs(body.angularVelocity);
|
body.angularSpeed = Math.abs(body.angularVelocity);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue