Definition of the gravity assist are (spaceflight) a trajectory that passes close to a planetary body in order to gain energy from its gravitational field .