schteppe / cannon.js

A lightweight 3D physics engine written in JavaScript.
http://schteppe.github.com/cannon.js
MIT License
4.69k stars 712 forks source link

Cannon.js collision - preservation of energy #441

Open cosentino-smeup opened 4 years ago

cosentino-smeup commented 4 years ago

Hello, I’m using cannon.js to handle collisions in threejs and it’s working fine except for one case: I need the collision between a sphere and a box doesn’t make them lose energy so they can preserve their velocity. The box body is STATIC.

Is it possible?

As you can see in the following demo after the collision, the sphere lose energy and start going slower.

cannonjs-walls-collision.zip

This is the build folder: build.zip

Thanks, Regards

Dannie226 commented 3 years ago

You should be able to make a contact material between the two bodies and set restitution to 1 so no energy is lost on bouncing

Dannie226 commented 3 years ago

here is a zip file containing the example. Uses cdns (three.js)/base repo code (cannon.js, orbitcontrols) so no need to download new libraries. cannonjs-walls-collision.zip