From: martin AT loplop DOT com (Martin Peach) Newsgroups: comp.os.msdos.djgpp Subject: Re: Help implementing gravity in a scorched earth like game Date: Mon, 27 Apr 1998 19:18:23 -0400 Organization: LopLop Inc. Lines: 40 Message-ID: References: <1998042721391500 DOT RAA08930 AT ladder01 DOT news DOT aol DOT com> NNTP-Posting-Host: dialup-639.hip.cam.org To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article <1998042721391500 DOT RAA08930 AT ladder01 DOT news DOT aol DOT com>, funkdog32 AT aol DOT com (Funkdog32) wrote: >Hey all... I have been working on a program much like scorch lately... It is >going well and the rockets, bombs etc. look like they're being influenced by >gravity but it just doesn't look quite right. I would love for someone to give >me a formula for it = ) At every time step the velocity in the z-direction (up is positive) will change by (-G*M/(r*r)) where M is the (constant) mass of the Earth or whatever, r is the (variable) distance from the centre of the Earth to the rocket, and G is the gravitational constant, the real value of which you can find, but is only valid for time steps of one second. So the best thing is to fiddle with GM until you get a reasonable looking result (or divide the real G*M by the_number_of_time_steps_per_second_in_your_program). The mass of the rocket has almost no effect on its acceleration (below warp speed:>). If you are on a flat planet (z always points to the centre of the planet) then r*r is just the square of the distance along the z-axis from the centre of the planet to the rocket. In outer space you have to work in 3d and do three calculations per time step, one for each axis. r*r is ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2)) where x1,y1,z1 is the 3d location of the rocket, x2,y2,z2 is the centre of the planet. The acceleration along the x-axis, say, is then -((x1-x2)/sqrt(r*r)) * (GM/(r*r)). Of course, you need to optimize for speed by not doing the same calculation twice. ...Martin.- \ \ | | | * ______________________ -- \/\/\/\/\*=