Collision and Separation events

Topics: Developer Forum
Feb 11, 2009 at 10:14 AM
I'm catching the OnCollision and OnSeparation events of a area that as CollisionResponseEnabled = false.
I only want to know that some other objects are over that area and don't want the objects to collide with this area.

area1.OnCollision += OnCollision;
area1.OnSeparation += OnSeparation;

In order to debug these events I'm setting a textbox with the name of the event
private bool OnCollision(Geom geom1, Geom geom2, ContactList cl)
  txtStatus.Text +=
  return false;

void OnSeparation(Geom geom1, Geom geom2)
  txtStatus.Text +=

When an object gets in contact with the area I have a series of Collision and Separation events and not just one:
Collision, Separation,Collision, Separation,Collision, Separation,Collision, Separation,Collision, Separation,
Collision, Separation,Collision, Separation,Collision, Separation,Collision, Separation,Collision, Separation,...

Is this the expected behaviour ?


Feb 11, 2009 at 7:15 PM
It's a part of the engine design so you will have to work around it if you want another behavior.
Whenever two geometries collide, they overlap each other a little, an impulse is applied to the geometries to correct this (That's actually how physics behave.) and therefore they will separate. If two geometries are sitting next to each other, they will constantly collide (and also separate).

You can probably get around this by averaging 3 updates. If the geometries collide in update 1, they collide. If they don't in update 2, they still collide, if they still don't in update 3, they don't collide anymore. Does this make sense?
Feb 12, 2009 at 8:45 AM
Hi! Thank you for your answer :)
If that is the expected engine behavior I don't understand the benefit of the OnSeparation event.
The Separation event is fired after the collision event and when there is still a collision between the 2 objects. In my point of view the separation event should never be fired if the 2 geometries still collide. 

I can follow the suggestion to check for collisions on the update loop but then ... I would be "reinventing" the collision and separation events ...

Just to clarify, I have a rectangle and a ball. The collision, separation events are fired continuously when the ball passes over the rectangle ...
Feb 12, 2009 at 3:21 PM
Geometries only collide when they are touching, not when they are very close to each other. The same goes for the OnSeparation event, it only fires when geometries are not touching.
So, the separation event does indeed never fire when the 2 geometries still collide. If I were to implement something that made the events fire only when a real separation occurs, then it would not be precise enough. Could perhaps make a threshold or something. If the geometries are 1px apart the separate event would fire and not before. But then again, when the geometries are 0.01 apart, they are separated.