How can I create a vacuum cleaner or magent using Box2D?

Hi!

Is there any way to create a vacuum cleaner or magent using Box2D?
There is a demo called "Sensor Test" where I can see how some objets are attracted to another one, but I don't know if this is what I'm looking for, as I read sensors are designed to collect collision information.

Please, see attached picture explaining what I want.


Image


Thanks for suggestions.
Well, looking at that picture, a sensor is exactly what you'd want to use!

The big circle would be your sensor. Once the apple enters the circle, a collision will be generated with the sensor shape, (you will receive contact events).

Then you know the object is within range, and you simply apply the appropriate force, in this case, I would say you need to apply a force towards the horizontal center of the big circle. Something like:
Code:
force = new b2Vec2(sensor.GetPosition().x - apple.GetPosition().x, 0);
apple.ApplyForce(force ,apple.GetPosition());
android has it right. Just make sure the force is also a product of the distance from the source of the "attraction". The farther away, the less the force applied.

Bill
Thanks for your help.

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