Tutorial 2 – Orbits

This tutorial demonstrates how to setup bodies in orbits around a “star”. “Star” refers to a body that has larger mass than any of the bodies orbiting it (e.g. a factor of 50 or more.)

  1. Begin with an empty scene.
  2. Create an GravityEngine (GameObject/3D Object/GravityEngine)
  3. Add an Nbody prefab to the scene.
    1. Set the mass to 1000
    2. Set the scale of the NBodyModel child to (5,5,5).
    3. Rename the parent to “Star”
  4. Add a PlanetInOrbit prefab to the scene and then drag it onto the “Star”.
  5. Select the planet.
    1. The Editor panel contains a component “Elliptical Start”. The parameters here control the shape of the orbit.
  6. Set the camera Z position to zoom out to see both the star and planet.
  7. Press PLAY.
    1. The planet will move in a circle at a fixed radius
  8. Press stop.
  9. Adjust the orbit settings and get a feel for how the affect the orbit. As you change the parameters the orbit path in the Scene window will be updated.

Some Comments:

The planet motion is evolved using the gravitational force calculated as the scene evolves. The predicted orbit in the editor window assumes the planet and the star are the only objects interacting. If you have other planets and stars the resulting orbit will not be exactly as show. (Predicting the exact orbit when even three bodies are present is not solvable in general and is know as “The Three Body Problem”).

The planets gravity will move the star by a small amount. In general this will cause the star to drift in the scene. There are several solutions.

  1. A FixedObject component (in Scripts/Orbits) can be added to the star. The GravityEngine will detect this and the position of the star will not be updated.
  2. If you have only two bodies, instead of using a Planet with an OrbitEllipse component, create a binary system (see the Binary Tutorial below).
  3. The star can be given a velocity to offset the drift. (Aside: is it worth doing this automatically? Can we for multiple planets? Could have NBE report CM position and CM velocity…)
  4. The camera can be made to follow the center of mass of the system. (See X)

Compound systems can be created. For example you can add the third PlanetInOrbit and make it a child of the existing planet – as a moon. Generally the moon should have a smaller (10x) mass than the planet.

The Planet prefab makes the planet a full participant in the gravitational evolution. As more planets are added the computation requires the force between every NBody object in the scene to be evaluated. If the planets are not expected to influence each other then it can be better to move the planets in a fixed path due to the star’s gravity, ignoring the gravity from other planets. This can be done by selecting the KEPLERS_EQN mode for the OrbitEllipse component.