How to use the matter-js.Body.setPosition 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
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 cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / Crate.ts View on Github external
update(dt: number){
        if (this.owner != null && this.action != "throw" && this.action != "break") {
            if (this.owner.action == "hide") {
                Body.setPosition(this.body, this.owner.body.position);
                this.action = "idle";
            }else{
                Body.setPosition(this.body, Vector.add(this.owner.body.position, this.offset));
                this.action = "hold";
            }
        }

        if(this.action == "break"){
            if(this.delayOnRemove <= 0){
                this.destroy();
            }else{
                this.delayOnRemove -= dt;
            }
        }

        if(this.action == "throw"){
github cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / Crate.ts View on Github external
update(dt: number){
        if (this.owner != null && this.action != "throw" && this.action != "break") {
            if (this.owner.action == "hide") {
                Body.setPosition(this.body, this.owner.body.position);
                this.action = "idle";
            }else{
                Body.setPosition(this.body, Vector.add(this.owner.body.position, this.offset));
                this.action = "hold";
            }
        }

        if(this.action == "break"){
            if(this.delayOnRemove <= 0){
                this.destroy();
            }else{
                this.delayOnRemove -= dt;
            }
        }

        if(this.action == "throw"){
            if (this.throwRecoverTime < this.delayOnThrowRecover){
                this.throwRecoverTime += dt;
            }else{