notification of non-physics collisions

Apr 9, 2010 at 8:10 PM


Is there a way to be notified about two bodies overlapping without having a physics collision? Clearly setting body.isSensor=true is the right way to do this for many cases, but what about two bodies that both want to avoid bumping other things (so isSensor=true), but still want to be notified of overlaps?

The reason I want to do this is I want to quickly be able to have a game entity "see" all other entities within a certain range (some of which might not bump into stuff). To do this, I am adding to that entity an extra fixture shaped like a circle with radius equal to the sight range, and setting isSensor = true (and doing stuff in its user data to help me remember its purpose).

The way I make it work, right now, is by having my own quad-tree lookup for entities and using that to find those nearby. Clearly a duplication of effort.

Any tips?

- John

Apr 9, 2010 at 10:08 PM

You have 3 options.

1) Like you said, add a extra fixture for the sensor and that will let you filter down to only the object the entity can see.
2) Do an AABB query around the entity to get a list of objects nearby (this is simpler than your own quad-tree because it's based off the internal dynamic tree)
3) Use raycast's to approximate the vision area.  I've done it where each entity spins a ray around itself (similar to radar) and remembers what it sees to build up a 'view' of the world.

Apr 9, 2010 at 11:04 PM

That #2 is exactly what I was looking for. Now that you call it an AABB query, I easily notice the method QueryAABB and work it into my stuff in 5 minutes.

I really appreciate the very prompt and extremely helpful responses you guys give. It's great to be basing a game off of code maintained by people like you. Thanks!

- John