I'm trying to write a simple game engine with gravitation between players and various things, but when objects get rather close the linear approximations get direly inaccurate, and I wanted to be able to keep energy conserved.

So I'm trying to work out this problem here, as the first step before taking it into vector calculus, which I know nothing about:

$\displaystyle \frac{d^2x}{dt^2} = \frac{k}{x^2}$ (note that k = m2*G, because m1a = (m1*m2*g)/x^2, and we assume that mass 2 is held in place... somehow....)

I don't quite know what to do with it, when I tried working it out I got this:

$\displaystyle \int x^2*\frac {d^2x}{dt^2}\ dt = \int -k \ dt$

$\displaystyle \int x^2*\frac {d^2x}{dt} = -kt$

$\displaystyle \int \frac {d}{dt} (x^2)\ dx = -kt$

But I don't believe I can find the derivative of x^2 with respect to t like this....

I am only in high school calculus, but can generally get a good quick grasp of math-stuffs, especially if I need it for programming stuffs like this. >.> But if this doesn't qualify as a differential equation as I suspected, just PM me if you move it to another section.

[edit]

I tried to take it a lot further with some substitutions and came up with some weird stuff with natural logs of negative numbers in it.

My logic is clearly screwy in how I try to manipulate the differentials, because if that worked, then so would this:

$\displaystyle \int \frac {d^2x}{dt^2}\ dt = \frac {dx}{dt}$

$\displaystyle \int \frac {d^2x}{dt} = \frac {dx}{dt}$

$\displaystyle \int \frac {d}{dt}\ dx = \frac {dx}{dt} \frac{d}{dt} \ \ \ \ (\frac {d}{dt}(1) = 0)$

$\displaystyle \int 0\ dx = C = \frac {dx}{dt}$

Which would imply that as long as an acceleration equation exists, velocity is constant, which definitely makes no sense.

So now I'm at a loss again. Can someone please help me out here?

[edit] For those interested, here's my most accurate (and complicated) attempt at a system of equations to show the behavior I need to solve for position over time.

$\displaystyle \frac{d^2x}{dt^2} = \frac{k}{x^2 + y^2} * cos\left(cos^{-1}\left[\frac{x}{x^2+y^2}\right]\right)$

$\displaystyle \frac{d^2y}{dt^2} = \frac{k}{x^2 + y^2} * sin\left(cos^{-1}\left[\frac{x}{x^2+y^2}\right]\right)$

where k = G*m2

And any help drafting a complete system of equations to represent the behavior ofndifferent particles gravitating toward one another, or the pointing out of any flaws in my current system (besides the fact that it only represents gravitation of one particle around another, stationary particle) would also be appreciated.