This project is read-only.

zero gravity area

Feb 5, 2010 at 9:53 PM

How can I create some zero gravity area (rect area) in box2dxna? For example: The world has gravity vector like this Vector(0f, 10f) , but I want to create in game some rectangle area without gravity (gravity vector is Vector(0f, 0f). Is it possible todo in box2xna ? Sorry for my poor English.

Feb 5, 2010 at 11:27 PM

Yes you should be able to use a sensor body for the rectangle area you describe.

The sensor can recieve contact notifications so it can know what it is touching each frame.

For each other body it is touching, compare their AABB to make sure that it is fully within the no-gravity sensor area (if that is what you want).

For those that are fully within the sensor area you should be able to just apply an equal but opposite force to the body to cancel the effect of gravity.

Note that doing this will not suddenly make the object stop, since gravity is an acceleration the body might still fly right through the box if it was going fast enough.

If you want the body to immediately stop and have no forces applied when it enters the sensor area then on first contact just set the bodies linear and angular velocities to 0 and maintain the upward anti-gravity force as described above.

Feb 6, 2010 at 6:46 PM

Thnx, that's what I need. :)