stationX
stationX

Reputation: 31

Any ideas on how to create accurate orbital gravity using box2d?

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!

Upvotes: 2

Views: 4670

Answers (1)

GatorQue
GatorQue

Reputation: 43

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.

Upvotes: 3

Related Questions