cannon.js
cannon.js copied to clipboard
Elastic collision
Is there a way to change the elasticity of collision, meaning how much energy is lost on impact? For example when hitting two sphere bodies, they lose most of their energy.
Check out the restitution
property in the ContactMaterial class. Set the value of this property to e.g., 1.0 to achieve the effect you're looking for.
I have the same problem. I have colliding spheres and I want no energy lost on collisions. I set the restitution to 1.0 but still the energy is lost. Any thoughts that might help?
var physicsMaterial = new CANNON.Material("bouncyMaterial");
var physicsContactMaterial = new CANNON.ContactMaterial(physicsMaterial,
physicsMaterial,
0.0, // friction coefficient
1.0 // restitution
);
// We must add the contact materials to the world
world.addContactMaterial(physicsContactMaterial);
... this.body = new CANNON.Body({ mass: this.mass, position: new CANNON.Vec3(this.loc.x, this.loc.y, 0), // m shape: new CANNON.Sphere(this.radius), velocity: new CANNON.Vec3(this.vel.x, this.vel.y, 0), linearDamping: 0, material: physicsMaterial });
I tried it with a cube moving along y axis between two boxes. The cube starts spinning after a few collisions. That explains why it loses energy.