I'm attempting to write a simulation of a solar system of planets in 2D space that are attracted to each other through Newton's law of universal gravitation.

I know that it is possible to simulate this in Box2D by applying forces between each body in the system each frame, however I've read that Box2D is tuned for objects between 0.1m and 10m - In my simulation I want to be able to simulate the motion of large and small bodies (e.g. planets and artificial satelites).

When such large scales are involved is using Box2D (or an alternative 2D physics engine) to simulate the gravity between bodies in this way a good idea (I know I can scale the system, e.g. so that the sun has a diameter of 10m), or am I better off doing this myself?

  • \$\begingroup\$ It depends, if you are interested in more than just the basic planet physics simulation I would use Box2D. Box2D is a powerful tool and learning it will only benefit you. In addition adding in a physics engine makes it much much easier to cope with any sort of physical simulation you might want to add in later (bullets or shrapnel effected by gravity, ship's having realistic propulsion, ect...). \$\endgroup\$ – ClassicThunder Apr 8 '13 at 13:30
  • \$\begingroup\$ If you want to include collisions, I think you should try to use Box2D \$\endgroup\$ – fableal Apr 8 '13 at 13:33
  • \$\begingroup\$ @fableal I'm not 100% sure at this stage whether or not I will include collisions, however it seems fairly likely \$\endgroup\$ – Justin Apr 8 '13 at 13:37

If you can write an n-body simulation yourself, then it will ultimately give you significantly more control over the accuracy of the simulation. Is the goal of your simulation performance, or accuracy? Box2D is designed to be a real time physics engine, so it is geared more towards high performance simulations, meaning it will make assumptions where necessary to provide the best performance without sacrificing too much precision. You will be able to make it work, but it simply depends on what your goals are.

edit this is a characteristic that is true of all real time physics engines. I have found myself encountering this problem over and over when trying to use a physics engine for something that is a bit unorthodox or simply not what it was intended for.

| improve this answer | |
  • \$\begingroup\$ The goal is for enough accuracy and performance to build a game on top of the simulation - ultimately I would sacrifice accuracy to ensure that the simulation runs in real-time, however not to the point where it seems "unrealistic" or "buggy" (although I realise that in reality what is "unrealistic" in a game is very subjective) \$\endgroup\$ – Justin Apr 8 '13 at 13:40
  • \$\begingroup\$ At this point then, I would choose the physics middleware, and simply work with it until i get the results I wanted. You could roll your own, but if you plan on taking this game beyond something fun to do in your free time, or unless you REALLY want to write a physics package, Box2D is going to get you what you want. \$\endgroup\$ – Evan Apr 8 '13 at 13:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.