Skip to content

Commit

Permalink
derive velocity from position in setters
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jan 5, 2022
1 parent fe98528 commit b6de9ed
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/body/Body.js
Expand Up @@ -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);
};

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

Expand Down

1 comment on commit b6de9ed

@adamschwartz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

Please sign in to comment.