###

» Sat Jan 18, 2014 1:50 am

Hi Zetar,

I finally got around to looking for a solution to this. The formula for the initial velocity from wikipedia is:

v=sqrt(G*M/r)

where G is the gravitational constant, M is the mass of the object being orbited and r is the distance. Since we aren't dealing with real distances we can just use 1 instead of G.

In my tests I didn't use the gravitation plugin, instead I just applied a gravitational force to the planet every tick:

G*m1*m2/r^2 or

sun.Physics.Mass*Self.Physics.Mass/distance(sun.X,sun.Y,Self.X,Self.y)^2

applied toward sun.x,sun.y

The biggest issue was that box2d units are odd so I had to find a conversion factor, which ended up being about 48.8.

So my final formula for the planet's impulse was:

Self.Physics.Mass*sqrt(sun.Physics.Mass/distance(sun.X,sun.Y,Self.X,Self.y))/48.8

Plugging that into your capx worked, but the orbits aren't perfectly round when using the gravitation plugin.