1

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?

Vahe Muradyan
  • 1,115
  • 1
  • 11
  • 22
  • 1
    you 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 Answers3

0

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.

KGSB
  • 39
  • 7
0

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

iforce2d
  • 8,194
  • 3
  • 29
  • 40
0

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.

Andrew Lundgren
  • 1,134
  • 1
  • 12
  • 18