How to use the matter-js.Body.setVelocity function in matter-js

To help you get started, we’ve selected a few matter-js examples, based on popular ways it is used in public projects.

github vibertthio / runn / src / renderer / avatar.js View on Github external
jump(v = -1.0) {
    const vy = this.body.velocity.y;
    if (Math.abs(vy) > 0.01) {
      return;
    }

    const finalV = v * this.physic.hUnit;
    Body.setVelocity(this.body, { x: this.body.velocity.x, y: finalV });
  }
github vibertthio / runn / src / renderer / avatar.js View on Github external
moveLeft() {
    const x = this.body.velocity.x;
    const finalX = (-this.speedLimit - x) * this.accelRatio + x;
    Body.setVelocity(this.body, { x: finalX, y: this.body.velocity.y });
  }
github vibertthio / runn / src / renderer / avatar.js View on Github external
moveRight() {
    const x = this.body.velocity.x;
    const finalX = (this.speedLimit - x) * this.accelRatio + x;
    Body.setVelocity(this.body, { x: finalX, y: this.body.velocity.y });
  }
github vibertthio / runn / src / renderer / avatar.js View on Github external
reset() {
    const { notes, totalQuantizedSteps } = this.renderer.melodies[0];
    const unit = this.renderer.width * 4 / totalQuantizedSteps;

    const add = (this.id === 0) ? 1 : 1;
    const yPos = (this.id === 0) ? this.renderer.height * 0.25 : this.renderer.height * 0.5;
    Body.setPosition(this.body, { x: (notes[0].quantizedStartStep + add) * unit, y: yPos });
    Body.setVelocity(this.body, { x: 0, y: 0 });
  }
github vibertthio / runn / src / renderer / avatar.js View on Github external
moveStopping() {
    const x = this.body.velocity.x;
    const finalX = (Math.abs(x * 0.8) < 0.01) ? 0 : x * 0.8;

    Body.setVelocity(this.body, { x: finalX, y: this.body.velocity.y });
  }