Skip to content

Commit b6de9ed

Browse files
committed
derive velocity from position in setters
1 parent fe98528 commit b6de9ed

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/body/Body.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ var Axes = require('../geometry/Axes');
549549
var timeScale = body.deltaTime / Body.timeUnit;
550550
body.positionPrev.x = body.position.x - velocity.x * timeScale;
551551
body.positionPrev.y = body.position.y - velocity.y * timeScale;
552-
body.velocity.x = velocity.x * timeScale;
553-
body.velocity.y = velocity.y * timeScale;
552+
body.velocity.x = (body.position.x - body.positionPrev.x) / timeScale;
553+
body.velocity.y = (body.position.y - body.positionPrev.y) / timeScale;
554554
body.speed = Vector.magnitude(body.velocity);
555555
};
556556

@@ -599,7 +599,7 @@ var Axes = require('../geometry/Axes');
599599
Body.setAngularVelocity = function(body, velocity) {
600600
var timeScale = body.deltaTime / Body.timeUnit;
601601
body.anglePrev = body.angle - velocity * timeScale;
602-
body.angularVelocity = velocity * timeScale;
602+
body.angularVelocity = (body.angle - body.anglePrev) / timeScale;
603603
body.angularSpeed = Math.abs(body.angularVelocity);
604604
};
605605

0 commit comments

Comments
 (0)