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.)
- Begin with an empty scene.
- Create an GravityEngine (GameObject/3D Object/GravityEngine)
- Add an Nbody prefab to the scene.
- Set the mass to 1000
- Set the scale of the NBodyModel child to (5,5,5).
- Rename the parent to “Star”
- Add a PlanetInOrbit prefab to the scene and then drag it onto the “Star”.
- Select the planet.
- The Editor panel contains a component “Elliptical Start”. The parameters here control the shape of the orbit.
- Set the camera Z position to zoom out to see both the star and planet.
- Press PLAY.
- The planet will move in a circle at a fixed radius
- Press stop.
- 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.
- 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.
- If you have only two bodies, instead of using a Planet with an OrbitEllipse component, create a binary system (see the Binary Tutorial below).
- 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…)
- 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.