Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Byte56, Josh Petrie, bummzack, Anko, Trevor Powell Apr 9 '13 at 8:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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...). –  ClassicThunder Apr 8 '13 at 13:30
    
If you want to include collisions, I think you should try to use Box2D –  fableal Apr 8 '13 at 13:33
    
@fableal I'm not 100% sure at this stage whether or not I will include collisions, however it seems fairly likely –  Justin Apr 8 '13 at 13:37

1 Answer 1

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.

share|improve this answer
    
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) –  Justin Apr 8 '13 at 13:40
    
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. –  Evan Apr 8 '13 at 13:43

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