I'm putting together a game that will be played mostly with three dimensional gravity.

By that I mean multiple planets/stars/moons behaving realistically, and path plotting and path prediction in the gravity field.

I have looked at a variety of physics engines, such as Bullet, tokamak or Newton, but none of them seem to be suitable, as I'd essentially have to re-write the gravity engine in their framework.

Do you know of a physics engine that is capable of dealing with multiple bodies all attracted to one another?

I don't need scenegraph management, or rendering, just core physics. (collision detection would be a bonus, as would rigid body dynamics).

My background is in physics, so I would be able to write an engine that uses Verlet integration or RK4 (or even Euler integration, if I had to) but I'd much rather adapt an off the shelf solution.

[edit]: There are some great resources for physics simulation of n-body problems online, and on stackoverflow

  • 7
    \$\begingroup\$ Can't you simply use Bullet and opt out of its standard gravity force somehow? (e.g. avoid calling applyGravity, call setGravity with a zero vector, use BT_DISABLE_WORLD_GRAVITY...) Just because your desired effect happens to be a form of gravity doesn't mean you need to be able to achieve it through the "gravity" APIs of the underlying physics engine. \$\endgroup\$ – Neverender Mar 15 '12 at 18:53
  • \$\begingroup\$ You could use some sort of inverse springs \$\endgroup\$ – Roy T. Mar 15 '12 at 19:16
  • 1
    \$\begingroup\$ @RoyT. A spring per se has a force proportional to d whereas gravity is d^(-2) (not even d^(-1)). You can get orbits from both, but with very different characteristics. If you just mean “use a distance-based constraint provided by the engine”, then yes — if it has an inverse-square one. \$\endgroup\$ – Kevin Reid Mar 15 '12 at 19:19
  • \$\begingroup\$ @KevinReid you're probably right, but I'm not sure I get your explanation. Do you mean spring forces are linear dependent on distance and gravity is inverse-square dependent? \$\endgroup\$ – Roy T. Mar 15 '12 at 19:39
  • 1
    \$\begingroup\$ Osmos is a great little game. the best I could find was this interview \$\endgroup\$ – brice Mar 16 '12 at 9:33

I don't think that you are going to be able to use a conventional timeslice physics engine because of the three body problem is not going to allow for stable orbits.

You might be able to yank the physics engine out of Stellarium or some other astronomy package.

However, I think the best course of action is to simply bake in your planet's paths and pull them out of a table. Unless your player can actually affect the trajectory of planets by his actions there is no point doing a full simulation.

  • \$\begingroup\$ Actually, w.r.t the N-body problem, you can get stable orbits. It depends on your method of integration. I've managed stable orbits with both verlet and RK4. \$\endgroup\$ – brice Jun 26 '12 at 20:59
  • \$\begingroup\$ It's a fair suggestion to pre compute the paths, but I'd like to dynamically generate the systems on the fly, and also, the planets are not really what I'm worried about. I actually want the ships to be affected by gravity, and since these will be under player control, can't pre compute the paths. \$\endgroup\$ – brice Jun 26 '12 at 21:01
  • \$\begingroup\$ The way to get stable orbits, for the record, is to make symmetrical systems. Also, the timescales for instability are much longer than the length of an average game would be. (unstable over 100s to 1000s of planetary orbits, while the game would not last longer than 4/5) \$\endgroup\$ – brice Jun 26 '12 at 21:05
  • \$\begingroup\$ For examples of stable orbits, have a look at this (uses Verlet) \$\endgroup\$ – brice Jun 26 '12 at 21:08

Is there any platform limitation? Because PhysX, from nVidia, has exactly what you are looking for, and more.

  • \$\begingroup\$ Cheers @YuriAlbuquerque that's quite an interesting lead. I'm planning to do the physics server-side and the rendering client--side, so I'll have to check whether it's suitable, but that sounds good. \$\endgroup\$ – brice Jun 26 '12 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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