Dynamic gravity for characters

I have some ideas for .

First, we have to think big. As in planetary bodies. Gravity should be treated as a force vector, proportionate to a mass ratio of a physical body (such as earth). The amount of gravitational force applied to a body is something like an inverse square law of its distance from that object (I’m sure a good physics book has a precise equation). If you have two bodies which exert gravitational forces on an object (such as the Earth and Moon), then to find the gravitational force vector applied to an object, we’d have to go through all gravitational forces, figure out the gravitational force from distance X towards the center position of each body, and come up with a sum of gravitational forces vector. force vector can then be applied as an acceleration force.

Optimization:
I think that may get computationally expensive with a lot of gravitational bodies, especially if they’re dynamic. I think that if you at least have a bunch of static gravitational bodies, you could go through chunks of 3D space and pre-generate a vector field which would suggest the sum of all gravitational forces at some position. The gravitational force applied could be determined by which cell you’re occupying and then querying its gravitational vector, and then applying it to the bodies in that field.

The “up” vector is an interesting one. As far as cameras are concerned, I’d keep the game model up vector unchanged, regardless of gravity because it keeps rendering consistent. But the “up” vector which suggests an up orientation could be set to the normalized inverse of the gravitational force vector. Jumping would cause an impulse force on vector (etc, etc).