Force Field

I have a body (Spaceship) made out of about 100 fixtures. I want it to have a force-field, so other bodies around it are repelled from it. I know the math, but should I be using a large sensor object, or repeated area querying around the ship to get the other bodies?

I started doing it with area query, but realized it had to sort through all its own fixtures first (I know how to filter, but it's just more expensive compared to if they just didn't pop up at all) So would a sensor object be better for this? Also for future reference, what are the comparative advantages and disadvantages of the two?
I think its obvious you want a sensor.

The main reason you'll want something like ray casting or AABB checks is when its a one time thing

For example, if you were to set off a bomb you could either

(Time Step)
(Game Step)
-create dummy body with a sensor

(Time Step) (bad as that allows the bodies another moment to act)
-Flag all collided Items
(GameStep)
-Destroy dummy
-apply effects to flagged

Or

(TimeStep)
(GameStep)
-Query AABB
-see if overlap is within radius
-cast ray to see if fixture is within radius
-Apply effects


In many ways your similating a sensor, however the difference is, you don't need that extra timestep

For you however, You won't create then destory. It will be a set it and forget it
I have it (almost) working, the problem now is how to get all the bodies that have fixtures contacting the force field. There are 3 ways I know of of doing this, neither of which will work well for different reasons. So I need another solution. Here are those solutions that don't work:

1. StartContact() of the Force Field(FF) fixture adds a pointer to the contacting bodies. End Contact removes that pointer. I loop over that every step to apply the force.
Problem: This won't work well because these bodies will be bullets, missiles, ect, which will get destroyed while inside the FF (because they hit the main part of the ship). So, I would need to implement a more complex system than just pointers to ensure the bodies don't get destroyed, leaving dangling pointers. In the manual:
End Contact Event
This is called when two fixtures cease to overlap. This is called for sensors and non-sensors. This may be called when a body is destroyed, so this event can occur outside the time step.
does that mean it CAN be called, or it is called?

2. Get the contact list for the whole body each step like so: m_contactList = m_pBody->GetContactList(); and apply the force to those bodies I find.
Problem: These are all the fixtures touching the entire body, not just the FF fixture, and the FF doesn't necessarily cover the whole body. The result is things hitting other parts of the body, and having a force applied to them when it shouldn't.

3. Use pre or post solve contact listener calls, which get called repeatedly throughout the collision of two bodies.
Problem: The pre and post solve functions are not called on sensors! 🙁 If they were, this would work!

TLDR: I need some way of getting the contact list for a sensor fixture.
I don't see why not just use 1.

If you're worried, test it.

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