Detecting if body is NOT colliding with anything

Dec 19, 2012 at 1:47 PM

I'm having a hard time to reliably check if a body is currently not touching/colliding with anything. I tried several approaches, eg. setting up a tracker to count collided bodies with nCollision and onSeperation events (sometimes the onSeperation does not fire as it should, and so the tracker never reaches 0), or using contactList, but to no avail.

The point of this is meant for constructing items on a level.

Could somebody point me in the right direction?

Dec 19, 2012 at 8:02 PM
Edited Dec 19, 2012 at 8:02 PM

Try this:

if (Body.ContactList == null)
 //no collisions
 //it has a collision with something

Dec 20, 2012 at 10:03 AM
Edited Dec 20, 2012 at 10:04 AM

Thanks, as I mentioned earlier I already tried this approach, but I have a few problems with it:


In this situation, the contactList is null, which is fine:

First problem. I need to move the body with the mouse, so I set the bodyType to static, but the contactList is null when touching other static bodies:

Second problem. The contact is detected before the bodies touch:


This is even more visible when one of the bodies is rotated:


What I would like to do is detect when the bodies actually touch:

Dec 21, 2012 at 4:33 AM

You never said anything about a static body being moved with the mouse. This is not really something that can happen in the real world, and that is why we don't try to simulate it in the engine. There are several problems you have run into related to the static body:

1. Static bodies can by definition not move (they are static...) and thus, they can't apply force to sleeping bodies.

2. Static bodies can't create contacts with other static bodies. They might overlap, but since none of them can move, there is no need to create a contact between them.

The only way of doing this reliably in the engine, is to use joints to move the body. What are you trying to achieve?

Dec 21, 2012 at 8:31 AM
Genbox wrote:

The only way of doing this reliably in the engine, is to use joints to move the body. What are you trying to achieve?

Not sure how I would do this with joints.. I'm trying to achieve a construction system - I choose an item type from a menu, which spawns a sensor body. If The body is not colliding with anything, I can place it on the ground.

Forgot to mention why I'm using a static body: when using dynamic, the contactList does not empty itself after seperation with another body. This issue does not occur when using static. Also, problem #2 from my previous post is the same when using dynamic or static.