// Use this for initialization void Start() { GravityEngine ge = GravityEngine.Instance(); time.text = string.Format(time_format, ge.GetTimeWorldSeconds(), ge.GetTimeZoom()); Vector3 pos = ship.initialPos; position.text = string.Format(pos_format, pos.x, pos.y, pos.z); velocity.text = string.Format(vel_format, 0f, 0f, 0f); if (rocketEngine == null) { Debug.LogError("Need a rocket component"); } fuelText.text = string.Format(fuel_format, rocketEngine.GetFuel()); attitude.text = string.Format(attitude_format, 0f, 0f, 0f); // assume earth at (0,0,0) initial_altitude = Vector3.Magnitude(ship.transform.position) - (float)atmosphere.heightEarthSurface; altitude.text = string.Format(altitude_format, initial_altitude); if (drag != null) { drag.text = string.Format(drag_format, atmosphere.GetAccelSI()); } if (accel != null) { accel.text = string.Format(accel_format, earthRocket.GetAccel()); } if (thrust != null) { thrust.text = string.Format(thrust_format, 100f); } }
public void SetTextInfo(float fuel, Vector3 angles) { GravityEngine ge = GravityEngine.Instance(); time.text = string.Format(time_format, ge.GetTimeWorldSeconds(), ge.GetTimeZoom()); double[] r = new double[3]; double[] v = new double[3]; GravityEngine.Instance().GetPositionVelocityScaled(ship, ref r, ref v); position.text = string.Format(pos_format, r[0], r[1], r[2]); velocity.text = string.Format(vel_format, v[0], v[1], v[2]); fuelText.text = string.Format(fuel_format, fuel); attitude.text = string.Format(attitude_format, angles.y, angles.x, angles.z); altitudeNow = Vector3.Magnitude(ship.transform.position) - (float)atmosphere.heightEarthSurface; altitude.text = string.Format(altitude_format, altitudeNow); if (drag != null) { drag.text = string.Format(drag_format, atmosphere.GetAccelSI()); } if (accel != null) { accel.text = string.Format(accel_format, earthRocket.GetAccel()); } if (thrust != null) { thrust.text = string.Format(thrust_format, rocketEngine.GetThrottlePercent()); } }
// Update is called once per frame void FixedUpdate() { // monitor for engine start (not ideal, but avoids linking to LaunchUI script) if ((timeStarted < 0) && engine.engineOn) { timeStarted = ge.GetPhysicalTime(); float pitch0 = pitchCurve.Evaluate(0); Vector3 localVertical = Vector3.Normalize(ge.GetPhysicsPosition(ship) - ge.GetPhysicsPosition(earth)); lastAttitude = Vector3.Cross(localVertical, Vector3.forward); // forward = (0,0,1) lastAttitude = Quaternion.AngleAxis(pitch0, Vector3.forward) * lastAttitude; } if (timeStarted > 0) { float t = (float)(ge.GetTimeWorldSeconds() - timeStarted) / timeRangePhysical; t = Mathf.Clamp(t, 0f, 1f); // pitch in range 0..90 as curve goes 0..1 float pitch = pitchCurve.Evaluate(t) * 90.0f; // find the local vertical Vector3 localVertical = Vector3.Normalize(ge.GetPhysicsPosition(ship) - ge.GetPhysicsPosition(earth)); // First get local horizontal (this ordering of cross product assumes we want to go East) Vector3 attitude = Vector3.Cross(localVertical, Vector3.forward); // forward = (0,0,1) attitude = Quaternion.AngleAxis(pitch, Vector3.forward) * attitude; engine.SetThrustAxis(-attitude); shipModel.RotateToVector(attitude); // when attitude changes by 1 degree, re-compute trajectories if (Vector3.Angle(attitude, lastAttitude) > 1f) { ge.TrajectoryRestart(); lastAttitude = attitude; } // thrust float thrust = thrustCurve.Evaluate(t); engine.SetThrottlePercent(100f * thrust); } }