p2.js
p2.js copied to clipboard
[Feature Request ] Disable collisions once disables all following contact equations.
I move this from the comment in https://github.com/schteppe/p2.js/issues/67 into this separate issue, I have problems to find it, I don't want to loose this idea :)
Hi,
contactEquation.enabled = false
allows us to cancel an equation only in preSolve
. It's technically possible to set this flag in onBeginContact
, but without an effect, as this is only a single equation out of dozens for the contact.
In box2d you can do this to disable the contact
beginContact: function(){
contact->SetEnabled(false);
in p2 you have to do it during the preSolve
- which is dispatched dozens of times as longs as the contact happens.
preSolve: function(){
contact.enabled = false
}
or if you depend on the beginning state (because you want to measure the angle, speed or whatever)
beginContact: function(){
//set some proprietary attribute (the contact equation will be reused and is no reliable place to do so)
contact.shape.passthrough = true
endContact: function(){
if (contact.shape.passthrough){
contact.enabled = false
The reason to do it in preSolve or with that passthrough
flag is that the enabled state is not stored over the whole contact, isn't it ? If you would store the enabled flag (I'm looking at you OverlapKeeper) from the first event which is the onBeginContact
we could do it like most people would try it in the first place:
beginContact: function(){
contact.enabled = false
I do not want you to mimic box2d, but I think it's more natural to say 'cancel' in the beginning- and then it should be cancelled- including the collision that follows after onBeginContact.
What do you think ? Thanks George
Sounds reasonable! Will experiment with this when I get some time over.
Has this been implemented? How can I disable contact response in the beginContact callback?