| | | 1 | | using System; |
| | | 2 | | using UnityEngine; |
| | | 3 | | |
| | | 4 | | // Physical constants. |
| | | 5 | | public static class Constants { |
| | | 6 | | public const float kAirDensity = 1.204f; // Sea level air density in kg/m^3. |
| | | 7 | | public const float kAirDensityScaleHeight = 10.4f; // Scale height in km. |
| | 1 | 8 | | public static readonly float kGravity = -Physics.gravity.y; // Standard gravity in m/s^2. |
| | | 9 | | public const float kEarthMeanRadius = 6378137f; // Earth's mean radius in meters. |
| | | 10 | | |
| | 0 | 11 | | public static float CalculateAirDensityAtAltitude(float altitude) { |
| | 0 | 12 | | return kAirDensity * MathF.Exp(-altitude / (kAirDensityScaleHeight * 1000)); |
| | 0 | 13 | | } |
| | | 14 | | |
| | 0 | 15 | | public static float CalculateGravityAtAltitude(float altitude) { |
| | 0 | 16 | | return kGravity * MathF.Pow(kEarthMeanRadius / (kEarthMeanRadius + altitude), 2); |
| | 0 | 17 | | } |
| | | 18 | | } |