Implementing gravitational fields in a 3d space combat game, and a rudimentary physics layer

So I’ve reached a decision about my game. I need to have planets which orbit a central star, with gravitational pulls of their own.

The biggest problem with this is my game ships are all controlled via altering transforms. I don’t use Unity physics much if at all.

In fact realistic physics with this control scheme are so wrong for this game as to make it unplayable. One collision or wrong turn and the ship is out of control for good (trust me, I’ve tried it).

So basically I need to create a simple gravitation system, with a physics layer that could be used for other (related) things.

The custom physics layer would be used to keep the ships from spinning wildly out of control, while still maintaining the control scheme (by ignoring physics for some objects like ship controls)

How difficult would it be to do this? I know some Calculus (I passed differential calculus!) and I’ve been reading the beginning of a physics book (for dummies!) and comprehending it quite well.

What would be the best path to achieve this? Any resources you guys know of that would aid this?

edit: the planets themselves don’t need to have their orbits calculated, though being convincing in their orbits for their mass and size would be ideal. I was thinking of putting them on rails, so we don’t have orbits degrading and planets colliding in an otherwise stable star system.

Additionally how would one manage a convincing scale of planets in this game? I know Unity can only handle about 100k units in any direction, IDK how paging would work with this. Or how planets might be “Seen” from a distance if they aren’t yet loaded from said paging system.

44 views and no replies? Does anyone wanna offer some advice?

Hi,

Maybe a stale thread - but might help someone else.

If you want to put planets on rails, then you’re looking for Kepler’s equation. This is fairly easy to program (although you need to iterate to get the orbit as a function of time).

If you want the fun of figuring it all out I recommend “Moving Stars Around” as a way to learn about gravitational simulations. http://www.artcompsci.org/msa/web/vol_1/v1_web/v1_web.html There are a number of subtleties to do with how to update velocity and position and timestep choices.

If you want an “out of the box solution”, I have recently completed an asset Gravity Engine - which is now in the asset store.

PM

1 Like