Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to implement collision detection in latest JiglibX using this example . I choose creating callback. I try to detect collision only once. When object falls through another callback is invoked multiple times, not only once. Is there any way how to ignore other calls? Thanks for advice.

share|improve this question
up vote 1 down vote accepted

What you need is to create a system to manage this for you. I have a list of bodies that each body is colliding with at any given time, I build this list based on the events I receive from JigLibX. At the end of each physics simulation step I update the list. Any new entries in the list that weren't there during the last step are new collisions, and I will send out an event for each of those that I find. Any collisions that were there during the last step that aren't there now are collisions that have ended, and I send out an event for all of those. And any collisions that I receive that were already in the list I do nothing for. Here's a visualization

Simulation Step #      Collision pairs
1                      1<->2, 1<->3, 2<->4
2                      1<->3, 2<->4, 2<->5

My list for collisions is currently empty before step 1. After step one my list looks like:

Body    Collisions with
1       2, 3
2       1, 4
3       1
4       2

After simulation step 2, my list looks like this:

Body    Collisions with
1       3
2       4, 5 (new)
3       1
4       2
5       2 (new)

You can see here we have a collision in the above list that is new (2<->5), I would send out events for that collision. There is also a collision from the first list that is no longer in the list after step 2, and that is 1<->2, which I would send out events for as well.

Using a system like I've described above means that you only have to receive a collision event when a new collision occurs, or when a collision ends.

You can see this system implemented in the QuickStart Game Engine, which uses XNA with JigLibX, it's a free download.

I don't know of any way to make JigLibX not send collision events each frame. Each physics engine I've used did this every frame (simulation step).

share|improve this answer
thank you, I will take a look :-) – Vodáček Jun 26 '12 at 14:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.