schteppe / cannon.js

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

Body stuck in compound after collision #161

Open hekto opened 9 years ago

hekto commented 9 years ago

I modified the compound demo to show what I mean. Basically, I put a thin box above the compound and drop it so it hits the compound right between the eyes two box shapes.

When it collides, I would like the thin box to bounce off, just as it does if it hits the side of a shape, but instead it wedges itself between the two shapes in the compound.

Is there a way to avoid this behaviour?

The modifications i did to the demo was adding this code to around line 60 of compound.html (end of the Boxes scene):

var body2 = new CANNON.Body( { mass: 20 } );
body2.addShape( new CANNON.Box( new CANNON.Vec3( 0.05, 1, 1 ) ) );
body2.position.set( 0.4, 0, 40 );
world.add( body2 );
demo.addVisual( body2 );

See it here: http://marcus.hekto.net/cannon.js/demos/compound.html

v0.6.1

hekto commented 9 years ago

@schteppe any thoughts on this?

schteppe commented 9 years ago

Sorry for the late response.

Maybe use 3 larger boxes in the compound instead? Or change the scale of the scene, for example make your smaller box bigger. Or make the time step smaller.

You could also strategically put sphere shapes inside the compound that could help push the smaller box out.

The best solution for this problem would probably be continuous collision detection - but that is not implemented in Cannon.js yet.