karylo

CannonJS elastic collisions

Recommended Posts

A newbie with CannonJS, I want to have spheres collide with elasticity such that there is no loss of kinetic energy.

All the spheres have the same physicsMaterial and the ContactMaterial has friction = 0.0 and restitution = 1.0.

I was hoping that would give me 100% elastic collisions yet I see that the spheres lose significant energy with every collision.

Is there something else I could or should be doing?  TIA

 

    // Create a slippery material (friction coefficient = 0.0)
    // and very bouncy (restitution coefficient = 1.0)
    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);

  // CANNON body
  this.body = new CANNON.Body({
       mass: this.mass,
       position: this.loc,
       shape: new CANNON.Sphere(this.radius),
       velocity: this.vel,
       linearDamping: 0,
       material: physicsMaterial
    });

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.