Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What mathematics is needed for a lunar lander game?

I'd like to build a game to learn cocos2d. Lunar lander is the first exercise coming in my mind. Any pointer/source code/tutorial of the physics calculations required will be appreciated. Thanks!

like image 943
ohho Avatar asked Jun 25 '10 17:06

ohho


People also ask

How do you play lunar Lander game?

The player controls a lunar landing module viewed from the side and attempts to land safely on the Moon. The player can rotate the module and burn fuel to fire a thruster, attempting to gently land on marked areas. The scenario resets after every successful landing or crash, with new terrain, until no fuel remains.

How do you land a lunar lander?

In order to safely land a lunar module, it must have a speed near 0 m/s as it touches down on the moon's surface. The module must fire its thrusters as it descends, counteracting the downward acceleration due to gravity and thus reducing its speed as it nears the surface.


1 Answers

You'll need stuff like this:

  1. Newton's laws of motion in 2D.
  2. Ability to change effect of gravity. 9.8 m/s^2 is the right acceleration on earth, but you should be able to change this to the appropriate value for Mars, moon, Jupiter, etc.
  3. Ability to turn thrusters off and on to counteract the effect of gravity. Not a very interesting game if you don't, because every one ends in a crash.
  4. Way to relate duration of thruster fire with fuel consumption. If you don't manage fuel well you crash.
  5. Initial conditions (e.g., height above surface, initial velocity, initial fuel, etc.)

You'll start with initial conditions and loop over a number of time steps. At the end of each step you'll check the position and velocity. If the y-position above the surface is zero or negative you'll have landed. If the velocity is greater than a critical y-value you'll have a crash; less than the critical value means a safe, soft landing.

You'll solve Newton's equations of motion numerically. In your case it's four coupled, first order ordinary differential equations: rate of change of velocity in x- and y-directions and rate of change of position in x- and y-directions. If you have the thrusters in place you'll add another equation for conservation of mass for the fuel.

You can eliminate two equations if you assume that there are no x-components: the lunar lander moves perpendicular to the surface, the thruster force only has a non-zero component in the vertical direction. If that's true, you're down to three equations.

You'll do time stepping, so it'll be good to read up integration techniques like explicit Euler or implicit 5th order Runge-Kutta.

A challenging problem - not trivial. Good luck.

like image 107
duffymo Avatar answered Oct 01 '22 07:10

duffymo