Inertia and gravity. Combine to keep earth in orbit around the sun and the moon in orbit around the earth. Earth's gravity keeps pulling the moon towards it preventing the movie from moving in and straight line. At the same time the moon keeps moving ahead because of its inertia.