Is there an alternative to Sensors?

Hello,

For the project I'm working on I could potentially get away with using sensors to determine when a given shape overlaps another one. However, for the sake of dynamism I'm really going for a broad-phase + narrow phase test. The idea is to start with an world.queryAABB() and within the callback, perform a Collision.testOverlap() to see if a given shape actually touches the shape of whatever fixture was found.

The result is not quite what I expected though. It seems that an overlap is only detected when the center-point of my 'sensor' shape is found to intersect with the fixture's shape. This simply isn't good enough. I need to know when any portion of one shape overlaps the other. Now, since I've been having some strange issues with shape.computeAABB(), it may be possible that I just flubbed something up.

So basically it boils down to this: Do I need to use sensors for such high-fidelity overlap info or am I simply doing something wrong here?
The use-case you're describing is pretty much the purpose of sensors.

What version of the engine are you using? If you're using the 2.1.2.1 version, try the 2.1.2.2 snapshot. There was an issue with polygons in there, try your approach with that jar
Already using 2.1.2.2 The previous version was actually throwing exceptions when I attempted to use testOverlap().

The reason I'm doing it this way is because I want the ability to dynamically change the size and offset of the region I'm detecting. I'm intending it to be used for hit-boxes for characters where certain animations use different hit-boxes. Maybe I'm wrong, but it seems like a lot of extra overhead carrying around a bunch of sensors and then determining which one to use and which ones to ignore.

Just as a side note: When I used shape.computeAABB() it appears to only give me a bounding box that is a fraction of the size of the shape it was created for. And it just so happens that this aabb is located right in the middle of the shape (the shape itself is a box btw). Because of this I manually computed the aabb instead but it just seems a bit coincidental to me that the generated bounding box would be the same as the testOverlap()'s detection region.

I can post some code once I get back to my computer.
Oh geeze I feel dumb. I wasn't setting the R matrix for the transform passed to the testOverlap() call. I thought it would only affect rotation of the shape. Apparently it affects size too. 😳

Anyway, just to confirm, would this still be considered a viable option? To manually check shape collisions rather than use sensors? I know I can deactivate whole bodies when they are not needed but I don't see any way to deactivate individual fixtures on the body. It just seems like it would be a waste of power to constantly check sensors that aren't needed or to constantly add and delete sensors between frames.
You can set the collision/mask bits in the fixture's filter settings to zero, that will exclude them from collision checks.
irresistible force wrote:
You can set the collision/mask bits in the fixture's filter settings to zero, that will exclude them from collision checks.


Also, if the sensors are non-moving, then there should be no performance hit. If the sensors would be moving, that means at the very least the broadphase will be updating.

Original thread: https://box2d.org/forum/viewtopic.php?t=8117