Jump to content

P2 physics events onBeginContact / onEndContact


Recommended Posts

Hi all!


I want to do stuff when my player hits my scenery, and when he stops contact. This is the code I use to listen:

this.avatar.body.onBeginContact.add(this.playerBeginsContact, this);this.avatar.body.onEndContact.add(this.playerEndsContacts, this);
I get the onBeginContact events just fine, but I receive practically no onEndContact events like this.
Does anyone know why?
As a test, I gave my scenery a listener for the onEndContact event, and what do you know, it gets an event every time – but also for collisions that have nothing to do with it! (like player vs the world bounds). Why is that?! :)
Link to comment
Share on other sites

I'm doing some research on these events now and there definitely seems to be something wonky:


The basic principle is that contact happens between this.update and this.render, and will be drawn after this.render and before the next this.update. Once contact has begun, shapes are assumed to be overlapping until a matching end contact event occurs. 


BUT! It seems that onEndContact delivers the wrong payload, here's an illustration:



So it looks like it's firing off the first recorded onEndContact event for every following onEndContact. But I later managed to do this:




I looked back at what happened before, and if you take a look at the first image, you will find that this contact pairing was exactly where shape 116 was when I started to jump:




So I think it could be a case of the overlapKeeper returning the wrong index when asked which shapes are or aren't colliding, or maybe the storing is wonky already and fresh overlaps are only stored in the keeper when more overlaps end than it's currently thinking there are? Or that newly ended overlaps will only be added to the keeper if there are no overlaps at all? Something like that probably...

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 months later...

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...