Created
May 4, 2020 14:15
-
-
Save Draco18s/7f319c8c2606c66ac72d3564bb4f8718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///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