How to use the matter-js.Vector.mult 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.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / Character.ts View on Github external
if(this.action == "dead"){
            return;
        }

        if(this.mlb === true && this.entityInHand != null){
            this.action = "hide";
        }else if(this.mlb === false && this.action == "hide"){
            this.action = "idle";
        }

        this.mouseDistance = Vector.sub(this.mousePosition,this.body.position);
        // Body.setAngle(this.body, Vector.angle(Vector.create(0, 1), this.mouseDistance));

        if(this.action != "hide"){
            if (this.dirX != 0 || this.dirY != 0) {
                Body.translate(this.body, Vector.mult(Vector.create(this.dirX, this.dirY), this.speed));
                // Body.setVelocity(this.body,Vector.create(this.dirX*20,this.dirY*20));
                this.action = "move";
            } else {
                this.action = "idle";
            }
        }

        if (this.mrb === true && this.entityInHand != null) {
            this.throw();
        }
        
    }
github cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / Character.ts View on Github external
throw() {
        if (this.entityInHand != null) {
            let b: Body = this.entityInHand.body;
            let dir = Vector.normalise(Vector.sub(this.mousePosition, this.body.position));


            (this.entityInHand as PhysicsEntity).enablePhysics();

            this.entityInHand.action = "throw";
            Body.setPosition(b, Vector.add(this.body.position, Vector.mult(dir, 10)));
            // Body.setVelocity(b, Vector.mult(dir,3));
            Body.applyForce(b, b.position, Vector.mult(dir, 0.5));
            this.entityInHand = null;
            this.action = "idle";
        }
    }
github cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / Character.ts View on Github external
throw() {
        if (this.entityInHand != null) {
            let b: Body = this.entityInHand.body;
            let dir = Vector.normalise(Vector.sub(this.mousePosition, this.body.position));


            (this.entityInHand as PhysicsEntity).enablePhysics();

            this.entityInHand.action = "throw";
            Body.setPosition(b, Vector.add(this.body.position, Vector.mult(dir, 10)));
            // Body.setVelocity(b, Vector.mult(dir,3));
            Body.applyForce(b, b.position, Vector.mult(dir, 0.5));
            this.entityInHand = null;
            this.action = "idle";
        }
    }