Issues with Orbital Gravity

Hey everyone, I'm somewhat new to Box2D and I'm trying to utilize it in a game project. I'm working to simulate orbital gravity using an example posted by Nick Vellios here http://www.vellios.com/2010/06/06/box2d-and-radial-gravity-code/. I switched the syntax to AS3, but I'm getting weird results. Objects are drawn to the 'planets' at first, but then seem to sling shot around them:

http://gravitygame.pbworks.com/f/Orbital_Physics2.mov
http://gravitygame.pbworks.com/f/Orbital_Physics3.mov

I'm not sure why the objects won't just fall to the planet and stay there. Here's the code that I have in my update loop that handled the orbital gravity.

Code:
         for (var b:b2Body = m_world.GetBodyList();b;b = b.GetNext())
         {
            b.SetLinearDamping(10);
            var ground:b2Body = planetFixture.GetBody();
            var circle:b2CircleShape = (b2CircleShape)(planetFixture.GetShape());
            var center:b2Vec2 = ground.GetWorldPoint(circle.GetLocalPosition());
            var position:b2Vec2 = b.GetPosition();
            center.Subtract(position);
            var distance:b2Vec2 = center;
            var force:Number = 150.0 / distance.LengthSquared();
                      distance.Normalize();
            var F:b2Vec2 = new b2Vec2(distance.x*(force),distance.y*(force));
            //trace(position.x+" and "+position.y);
            b.ApplyForce(F,position);
         }


Any suggestions?
I had a similar problem, though not the same, in a flash project that wasn't using box2d (just simple physical equations).
But first, can you trace for the force being applied on one of the bodies? See its direction and magnitude over time?
Tapud, I put the following trace in my code from above ( Hopefully tracing the variables 'F' and 'position' from my code is what you meant by magnitude and direction).

this is the trace I added:
Code:
if(b.GetUserData() is Player)
{
trace("Force is: ("+F.x+","+F.y+") and position is: ("+position.x+","+position.y+").");
}


This trace is following the course of the black ball in http://gravitygame.pbworks.com/f/Orbital_Physics3.mov.

At First -
Force is: (0.40074804882182713,0.10929492240595284) and position is: (8.333333333333334,1.6666666666666667).
Force is: (0.40092285734017663,0.1093425974564118) and position is: (8.337330576433708,1.6677568238758593).
Force is: (0.4010672585866519,0.10938197961454142) and position is: (8.340630543213505,1.6686568148158043).

2 Seconds in
Force is: (0.5717586458975705,0.15593417615388297) and position is: (11.317995818418602,2.480665526235374).
Force is: (0.5788101270048986,0.15785730736497244) and position is: (11.411776591546232,2.5062421007247275).
Force is: (0.6016098883869795,0.16407542410554002) and position is: (11.703632759919948,2.585839237553922).

4 Seconds in
Force is: (2.3814367059873556,0.6494827379965521) and position is: (19.145977813076783,4.6155697065966965).
Force is: (2.962189593488413,0.8078698891332039) and position is: (19.92339405885816,4.827592319082528).
Force is: (3.2192218847010263,0.877969604918462) and position is: (20.198194893792845,4.902538001337442).

5 Seconds in
Force is: (4.710067177051034,1.2845637755593433) and position is: (21.319009067399136,5.208214594139192).
Force is: (4.7091975532239,1.2843266054246665) and position is: (21.318515327675843,5.208079937851026).
Force is: (4.704855447713833,1.2831423948309701) and position is: (21.3160479955566,5.2074070290912795).

6 Seconds in
Force is: (3.9985618130357445,2.7446547453521215) and position is: (22.081565367674038,3.5194050694660532).
Force is: (2.65254635958453,4.030652705084722) and position is: (23.60159161913249,2.0091597443121336).
Force is: (1.2040794800390073,4.671881731517368) and position is: (25.27506315240981,1.267183373785326).
Force is: (0.2375170250932906,4.845191523415145) and position is: (26.39440145197343,1.112634866907367).

(At this point it whips around the planet)

Force is: (-0.9492843274265322,4.7663385001364444) and position is: (27.75182749521759,1.2180948462679544).
Force is: (-2.0442348708099036,4.012285838563695) and position is: (29.286769175766615,1.524106805782355).
Force is: (-2.493819600998485,2.75863159121228) and position is: (30.925721550049364,1.955354210343706).
Force is: (-1.872781061147195,0.8872986151595573) and position is: (34.3551382197705,3.0239716911077856).
Force is: (-1.4506760444980988,0.4693609176805929) and position is: (36.10363251842129,3.613370950439105).
Force is: (-0.5513607574270835,0.018956279702004693) and position is: (43.146124274194534,6.100088063569503).
Force is: (-0.45080836201961155,-0.0016674213971552615) and position is: (44.90752170188826,6.734134785163567).
Force is: (-0.3742587342301416,-0.013156080886723926) and position is: (46.6679294639107,7.369758424133446).
Mmmmm, are you clearing your forces?
In the update function where you run the step function on your world:
Code:
public function Update (e:Event):void {
         myWorld.Step(myTimeStep, myVelocityIterations, myPositionIterations);
         myWorld.ClearForces();
      }   
Tapud, thanks for the advice! I cleared the forces like you suggested and tweaked a couple more variables and the results look a lot better. http://gravitygame.pbworks.com/f/Orbital_Physics4.mov. The black ball is controlled by keyboard input so that's why it's movements are a bit funny.

Original thread: https://box2d.org/forum/viewtopic.php?t=5555