cannon.js
cannon.js copied to clipboard
Body.addShape is not a function
Cannon version: cdnjs.cloudflare.com/ajax/libs/cannon.js/0.5.0/cannon.js
This is the part of cannon of my code:
var world = new CANNON.World();
//world.broadphase = new CANNON.NaiveBroadphase();
world.gravity.set(0, -9.8, 0);
//var debugRenderer = new THREE.CannonDebugRenderer(scene, world);
//var groundShape = new CANNON.Plane();
//var groundMaterial = new CANNON.Material();
//var groundBody = new CANNON.Body({mass: 0, material: groundMaterial, shape: groundShape, position: new CANNON.Vec3(0, -1, 0)});
//groundBody.quaternion.setFromAxisAngle(new CANNON.Vec3(1,0,0), -Math.PI/2);
var groundBody = new CANNON.Body({
mass: 0 // mass == 0 makes the body static
});
var groundShape = new CANNON.Plane();
groundBody.addShape(groundShape);
world.addBody(groundBody);
When I try to run it, it throws the error Uncaught TypeError: groundBody.addShape is not a function.
I thought the error happened because of the way I was creating the object (the commented part, creating a shape and a material, then creating the body with those). But then I literally copied the example in the README and it didn't work either.
Try groundBody.add. Usually one or the other works.