Open GuillaumeNachury opened 8 years ago
This should be pretty easy. I think you'll want to use body.applyImpulse
to objects within the radius of the explosion of the barrel.
Apply a greater impulse to objects which are further away from the barrel (1/radius
, maybe?).
Calculate the direction of the impulse with something like new CANNON.vec3.subVectors( otherBody.position, barrelBody.position)
. Not sure if the method is called subVectors
- but just use the method for vector subtraction.
Here is the impulse demo: https://schteppe.github.io/cannon.js/demos/impulses.html https://github.com/schteppe/cannon.js/blob/master/demos/impulses.html
Good luck!
Hi there, I'd like to create a kind of explosive barrel that may impact the surrounding objects. Can I get such behavior with cannon.js ?
Ty, G.