I want to create a game where is space , and to set the world gravity to the center of the earth so the object will fall on the earth from all sides , is it possible or no?
-
1you can check out [this question](http://stackoverflow.com/questions/25940650/how-to-create-whirlpool-vortex-effect) about how to create a body that attracts other bodes with gravity force. – kajacx Oct 12 '14 at 11:56
3 Answers
Yes it is possible. When making your "World" object give it:
World world = new World(new Vector2(0,0))
This is how you create a world in Farseer Physics, I have heard that Box2D and Farseer are very similar. Look for some Box2D tutorials, what you want seems very straight forward.

- 39
- 7
-
-
KGB I don't think you understand the question or maybe I don't. I think he wants do to something like this http://s11.postimg.org/93yziwu4z/path3016.png 0,0 would be no gravity.. – Boldijar Paul Oct 12 '14 at 09:46
You would need to set the gravity for the world to zero, and use ApplyForce to each dynamic body individually depending on where it currently is. The magnitude of the force to apply is the mass of the body multiplied by the gravity, and would be applied at the center of mass of the body. More info here: http://www.iforce2d.net/b2dtut/custom-gravity

- 8,194
- 3
- 29
- 40
I'm using Farseer which is a C# port of Box2D and generally one-to-one. I wrote my own gravity to accomplish this same thing and then realized that Farseer has it built in! Just add a GravityController to your world. Set its "point" to be the center of your planet. Works like a charm.

- 1,134
- 1
- 12
- 18