2
votes

I am trying to create an accurate orbital gravity system using box2d, basically; i want to be able to shoot a bullet on earth and depending on how fast this bullet goes, it will escape from earth, stay in orbit around earth or will land e.g.240 degrees or 45 degrees on the earth surface. (assuming, the bullet will fire at 0 degree) I did a lot of research and already dove into the physics laws of newton etc. Basic applyforce does not seem to do the job accurate enough. I also found the formula which calculates the needed velocity for an object to stay in orbit, and I managed to make this happen within box2d. However, if I want to stop the bullet, the bullet will not fall on earth again. (apply force is used for radial gravity and the second apply force is used to move the bullet to the "right" ) It will stay in orbit. Only if I add damping, the bullet will fall back to earth, but this seems wrong to me. When the bullet collides with something else, it also will damp.

i tought that the main issue here is to modify the velocity for the bullet. The bullet takes an x amount of time to land on lets say: 180 degree. How further away the bullet is from earth surface, the more velocity it takes to land on 180 degree the same amount of time. I think that velocity is the key to make true accurate radial gravity, but my question is; is this true, what do you guys think, does anyone have a similar scenario?? How does one control speed in the most proper way, without using damping and setlinearvelocity??

I also want to be able to control the speed needed to let the bullet orbit, escape or land back on earth. This should be possible, since there is also a formula that calculates the orbit velocity. E.g. When it goes wrong, the bullet is moving too fast, will escape from earth, but will move back, because earth gravity will modify the path of the bullet.

Btw: i did search a lot on internet, but cannot really link that stuff to practical box2d code, so i hope, someone can point me the right direction. Kind regards!

1
"Only if I add damping, the bullet will fall back to earth, but this seems wrong to me." Apparently there is a tiny amount of drag on real satellites, so that seems right to me. aero.org/capabilities/cords/faq1.html sorry can't help more :)iforce2d
Hm...that interesting, i though there is no air resistance in outer space...but this makes senses, of course there is...this also explains the gravity law...(objects would move forever in a straight line without forces etc) anyhow...in gues, it comes to tweaking and balancing out damping versus speed ....until yiu get it right. Is there formula that can calculate the needed damping to reduce velocity? Lets say, i want to decrease speed from 10 to 5 in 2 seconds, what should be the damping ratio? Thnx for pointing to this link...!! :-)stationX
That would be an acceleration of -2.5m/s/s, f = ma so you could ApplyForce of mass*2.5 for two seconds. Damping reduces the velocity of the body by a percentage every timestep so it's waaay harder to calculate.iforce2d

1 Answers

3
votes

I found this http://www.emanueleferonato.com/2012/03/28/simulate-radial-gravity-also-know-as-planet-gravity-with-box2d-as-seen-on-angry-birds-space/ gave a great example of doing radial gravity (planet gravity) using Box2D for ActionScript3 but can be easily ported to Box2D for C++. There are several Box2D examples for doing other tricks as well.