Version 9.2 updates the “mini-game” to demonstrate the launch of a rocket to Earth orbit from an arbitrary location to a specified inclination. The flight of the rocket can be controlled manually via keys or can be pre-programmed via curves for pitch and thrust versus time using the LaunchController component.
The goal of the mini-game is to provide a framework for scenes that require a launch to orbit and show how the various elements in Gravity Engine can be combined to make this happen. The scene models launch from the surface of the Earth making use of ORBITAL units. This sets a scale of 1km per Unity unit. The scene takes some liberty with the scale of the rocket and it’s stages and dynamically scales the model and paths in the scene based on whether the ship camera or orbit camera is being used.
This mini-game introduces a number of useful components:
- LatLongPoint Locates a point on the Earth surface given a latitude and longitude. There are some subtleties here described in the description below.
- MultiStageEngine: A class that allows up to 10 stages. Mass, thrust, fuel and burn rate can be entered for each stage. This class implements the GEExternalAcceleration interface.
- EarthAtmosphere: Models the velocity dependent air resistance (as a function of height) via the GEExternalAcceleration interface.
- EarthRocket: A script that combines the MultiStageEngine and EarthAtmosphere into a single GEExternalAcceleration component (since only one GEExternalAcceleration can be attached to an NBody)
- LaunchController: Controls pitch and thrust as a function of time based on curves provided in the inspector. Allows a target inclination to be specified for launch from a LatLongPoint.
- LaunchUI: Overall controller for the scene. Handles user input to start the engine, change ship attitude and manually trigger staging.
The rocket is powered by the MultiStageEngine script. This allows up to 10 stages to be specified in the inspector with mass/thrust/burn rate in SI units. The script also allows an optional Effect Object to be activated when the stage engine is on allowing control of e.g. particle systems to show exhaust. The specific value provided in the demo scene are similar to the values for a SpaceX Falcon 9.
Once the ship is under thrust the projected path of the object can be shown as a trajectory by enabling this feature in GravityEngine. This trajectory incorporates the continued thrust of the stage up to the point where its fuel is exhausted. If the LaunchController component is being used, the pitch and thrust are updated each frame and this will trigger a re-computation of the trajectory each frame, making the feature less useful. For this reason in the demo video trajectory prediction has been turned off.
The EarthAtmosphere component is described in detail on the <link> page.
Location on Earth
Placing the ship and launcher on the surface of the Earth requires some game design compromises. From a physics perspective we would like to place the the ship at exactly the correct radial distance from the center. However, the Earth is represented by a mesh and most points on the mesh are not at the exact radial distance. If we place the ship at the Earth’s radial distance the ship will either float above or lie below the mesh representing the Earth. A second issue is that the radial direction from the center will not be the normal of the particular triangle the ship is nearest, so it will not appear vertical. The LatLongPoint component is designed to solve these issues.
The LatLongPoint allows a user to specify a latitude and longitude for the launch point. It then sets the transform position to a location that matches the Earth mesh at this location and sets the transform orientation so that child objects to the LatLongPoint will be vertical on the Earth’s surface.
The typical use of the LatLongPoint is for it to serve as the parent to the components that model the launch site and the ship to be launched. It find the Nbody component of the ship as a child and sets it to match the radial position of the launch point based on the provided latitude and longitude.
The inspector for this component indicates the radial offset from the Earth radius (taken to correspond to the diameter of the sphere model) as well as the angle correction required to adjust the vertical direction. Note that once a launch starts the LaunchController will adjust the ship to the true normal.
LaunchController
The LaunchController component acts as an autopilot to direct the ship to a specific orbit inclination. It allows a configurable pitch and thrust curve which is applied during the ascent. Note that orbital mechanics dictates that the target inclination must equal or exceed the absolute value of the launch point latitude.
Games that prefer manual control of the ship during ascent can disable the launch controller and use the manual keys supported by the LaunchUI component.
Design of the Mini-Game
The scene implementation is based on a game controller class model using the LaunchUI script. The game controller loop handles:
- User interface state
- Ship maneuver commands
- Start engine/stage engine
- Automatically stage engine when fuel is exhausted.
- Selection of ship camera or Earth view camera via F1/F2 and re-scaling some elements in the scene as the camera is changed (using the LineScalar class as a helper)
Additional user interaction is handled in two other scripts:
- CameraSpin: Handles camera orientation and zoom via keys and mouse (and scales LineRenderers in the scene during zoom via the LineScalar class)
- TimeZoom: Adjust scene play speed as 1-5 are pressed
Dynamic position/velocity information is provided by the ShipInfo script.
Orbit information is presented by the OrbitParamPanel script after the rocket reaches an altitude of 50km.
There is more to do…
The launch scene does not currently handle the initial velocity imparted by the rotation of the Earth. This will be added in a future version of GE.
This is on the Trello board. If you want to nudge itup the list, send an email to nbodyphysics@gmail.com.