Skip to content

Instantly share code, notes, and snippets.

@Draco18s
Created May 4, 2020 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Draco18s/7f319c8c2606c66ac72d3564bb4f8718 to your computer and use it in GitHub Desktop.
Save Draco18s/7f319c8c2606c66ac72d3564bb4f8718 to your computer and use it in GitHub Desktop.
///Spend fuel and accelerate in direction
private void Thrust(Vector3 dir, float draw, float seconds) {
o.Normalize();
float change = GetVelocityFromBurn(this, draw * seconds);
DrawFuelFromTanks();
velocity += change*dir;
}
///Determine the number of seconds in order to reach velocity (assuming no friction)
public static float CalculateBurnTimeToReachVelocity(Spaceship ship, float vel, float draw) {
float totThrust = ship.GetTotalThrust(); //total thrust in kilonewtons
float totMass = ship.GetTotalMass(); //mass in kilograms
float dryMass = ship.GetDryMass();
float toBurn = totMass / (Mathf.Exp(vel / (totThrust*10)));
if(totMass-dryMass <= 0) return -1;
float t = (totMass - toBurn) / draw;
return t;
}
///Determine the resulting velocity from a given burn time
public static float GetVelocityFromBurn(Spaceship ship, float draw) {
float totMass = ship.GetTotalMass();
float dryMass = totMass - draw;
float totThrust = ship.GetTotalThrust();
return totThrust * 10 * Math.Log((float)totMass / dryMass);
}
///Calculate total available delta-v
public float TotalDeltaV() {
float totMass = GetTotalMass();
float dryMass = GetDryMass();
float totThrust = GetTotalThrust();
return totThrust * 10 * Math.Log((float)totMass / dryMass);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment