How to use the cannon.Body function in cannon

To help you get started, we’ve selected a few cannon 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 Bombanauts / Bombanauts / browser / game / Wall.js View on Github external
init() {
    /*----- CREATE WALL -----*/
    const wallBody = new CANNON.Body({ mass: 0 });
    wallBody.addShape(this.fixedCubeShape);
    const wallMesh = new THREE.Mesh(this.fixedCubeGeometry, this.material);

    /*----- SET SPAWN POSITION -----*/
    wallMesh.position.set(this.x, this.y, this.z);
    wallBody.position.set(this.x, this.y, this.z);

    scene.add(wallMesh);
    world.add(wallBody);

    this.wallMesh = wallMesh;
    this.wallBody = wallBody;
  }
}
github Bombanauts / Bombanauts / browser / game / FixedCube.js View on Github external
init() {
    /*----- CREATE FIXED CUBE -----*/
    const fixedCubeBody = new CANNON.Body({ mass: 0 });
    fixedCubeBody.addShape(this.fixedCubeShape);
    const fixedCubeMesh = new THREE.Mesh(this.fixedCubeGeometry, this.material);

    /*----- SETS SPAWN POSITION -----*/
    fixedCubeMesh.position.set(this.x, this.y, this.z);
    fixedCubeBody.position.set(fixedCubeMesh.position.x, fixedCubeMesh.position.y, fixedCubeMesh.position.z);

    scene.add(fixedCubeMesh);
    world.add(fixedCubeBody);

    this.fixedCubeMesh = fixedCubeMesh;
    this.fixedCubeBody = fixedCubeBody;
  }
}
github Bombanauts / Bombanauts / browser / game / Cube.js View on Github external
init() {
    /*----- CREATE PLAYER -----*/
    const cubeBox = new CANNON.Body({ mass: 0 });
    cubeBox.addShape(this.fixedCubeShape)
    const cubeMesh = new THREE.Mesh(this.fixedCubeGeometry, this.material);

    /*----- SETS SPAWN POSITION -----*/
    cubeMesh.position.set(this.x, this.y, this.z);
    cubeBox.position.set(cubeMesh.position.x, cubeMesh.position.y, cubeMesh.position.z);

    scene.add(cubeMesh)
    world.add(cubeBox)

    this.cubeMesh = cubeMesh;
    this.cubeBox = cubeBox;
  }

cannon

A lightweight 3D physics engine written in JavaScript.

MIT
Latest version published 9 years ago

Package Health Score

56 / 100
Full package analysis

Popular cannon functions