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

Collision Filters #347

Open gregmax17 opened 7 years ago

gregmax17 commented 7 years ago

I'm trying to get collisions to ignore one another while getting the collide callback.

I have a plane and 2 sphere bodies on top of it. When I have one of the sphere bodies collide with the other, I would like no collision response from the 2 sphere bodies, while getting a collide callback (I can't use the collisionResponse property because the spheres will then fall through the plane). When I set a group and mask on them it works, but again there is no callback.

Is there perhaps another way to do this? Can I use the world's preStep and postStep callbacks to get the collisions/contacts and disable them, or something?

schteppe commented 6 years ago

Hi, what I think you need is to be able to disable the contacts just before they are solved. At the moment I don’t think it’s possible (unless you monkey patch world.solver.solve()). In p2.js I added an event to the World called “preSolve” which would be useful here. I don’t think preStep would work since it is called after solve, and you need to do your stuff just before.

jamshidbro commented 5 years ago

You can also try "CollisionFilterMask" and "collisionfiltergroup" Read this. Its easy to understand https://github.com/schteppe/cannon.js/blob/master/demos/collisionFilter.html