schteppe / p2.js

JavaScript 2D physics library
Other
2.63k stars 329 forks source link

Ignore collision between bodies/players #316

Closed issy123 closed 6 years ago

issy123 commented 6 years ago

Hi,

I want the players to go through each other, thus ignore collision between players. The players still can collide with everything else. And I can still detect if a collision has occured between players.

Is this somehow possible??

With box2d you have collision filtering, but i don't think you can still detect collisions between same bodies.

schteppe commented 6 years ago

Hi. It’s indeed possible and it’s demonstrated in the character demo: https://github.com/schteppe/p2.js/blob/master/examples/canvas/character.html

The idea is to let the World generate contacts as it usually does, and then before contact solving you disable them. This will enable you to get events, but the contacts will not add contact force because you disable them.

issy123 commented 6 years ago

Thank you so much sir!

I will read into this when I have time

issy123 commented 6 years ago

hi @schteppe It works! But... When the player comes in contact with the body it does some small weird movement. Is there some collision or damping or anything before the 'preSolve' event?

issy123 commented 6 years ago

Wait...

I forgot the frictionEquations! It works 100% Thanks!