cannon.js icon indicating copy to clipboard operation
cannon.js copied to clipboard

Elastic collision

Open mgrzeszczak opened this issue 7 years ago • 3 comments

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.

mgrzeszczak avatar Feb 08 '18 17:02 mgrzeszczak

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.

amusaafir avatar Feb 10 '18 21:02 amusaafir

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 });

lorankary avatar Sep 11 '18 22:09 lorankary

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.

DiuDono avatar Aug 19 '22 12:08 DiuDono