After OnCollision event impossible to get the OnSeparation

Topics: Developer Forum, User Forum
Mar 31, 2011 at 9:40 AM


Before we start I wanna say thx to all the community. I leand lots of stuff by simply reading this forum :)

I'm posting this message because I haven't (yet) get the logic of the OnCollision.

I've create two entitys, the first one is Hero and the second one is PickableObject.

I want to know when this two entity are colliding and I want allow my hero to keep walking through the PickableObject.

I'm using the UserData to safe the reference of the body owner.


So I wrote this code for the Hero.OnCollision

bool Hero_OnCollision(Fixture fixtureAFixture fixtureBFarseerPhysics.Dynamics.Contacts.Contact contact)
            if ((Entity)fixtureB.UserData is PickableObject)
                this.isColliding = false;
                return false;
            return true;


and there is the OnCollision for my PickableItems.

bool PickableObject_OnCollision(Fixture fixtureAFixture fixtureBFarseerPhysics.Dynamics.Contacts.Contact contact)
           if (fixtureB.UserData is Hero)
                m_heroCollide = ((Hero)fixtureB.UserData);
                return true;
            return true;

That's great solution because my Hero is passing through my object and the collision is catched.

But (there is a but^^) I can't get the OnSeparation.

Nothing happend on the Hero OnSeparation and there is nothing on the PickableObject.

What did I miss ?

Cheers :)


Apr 4, 2011 at 8:47 AM
Edited Apr 4, 2011 at 8:47 AM



I know it's not really polite, I'm gonna re-up my message though  this post.

But I'm still looking for a solution to use this code as a trigger. :/

Does any one has an idea ?


Thx in advance ;)

Apr 4, 2011 at 9:09 AM

If you cancel the collision it is not taking place (duh)... hence no collosion => no onseparation afterwards. Since you cancel it each frame you could keep track of the (canceled) collision somewhere else by setting a bool to true. Afterwards just check for a canceled collision each frame. If there was no collision and your bool is true, set it to false and execute your onseparation logic. That is probably the hard way.

Since you just need to check for a collisions without a collision response, a sensor might be what you are looking for. Set Fixture.isSensor to true and i will produce collision events, without doing collision responses. If you need both, depending on which two objects collide, consider using two different fixtures (a sensor and a "normal" one) with appropriate collisiongroup settings. 

Apr 4, 2011 at 9:27 AM

the sensor solution seems to be what is Need.

I'm gonna try it asap. (I think I'll feel dumb again ^^)


Thx for your answer :)