/// <summary> /// Calculates and applies drag due to planetary gravity from a pre-calculated GravimetricResult /// </summary> /// <param name="grav">Pre-calculated GravimetricResult (contains a relative force of gravity and distance between planet and object at time of calculation)</param> public void ApplyDragDueToGravity(GravimetricResult grav) { //drag formula: atmospheric unit - (distance in megametres / scaling factor) = drag //example distant planet drag calc: 0.25 - (24457 / 100000) = 0.00543 = extremely low drag //example close planet drag calc: 0.25 - (1500 / 100000) = 0.235 = extremely high drag float drag = AtmosphericUnit - (grav.GetDistanceBetweenObjectAndBody() / ScaleFactor); //calculate drag from gravimetrics result's distance if (GetComponent <Rigidbody>().drag + drag > 0) { GetComponent <Rigidbody>().drag += drag; //ensure applying drag never results in a minus drag value } }
void FixedUpdate() { //apply gravimetric effect to object from all bodies GravimetricResult currentGrav = new GravimetricResult(new Vector3(0, 0, 0), 0); if (GetComponent <Atmospherics>()) { GetComponent <Atmospherics>().ResetDrag(); //reset drag so new calculation can be used } for (int i = 0; i < Bodies.Length; i++) { if (Bodies[i]) { currentGrav = GetGravity(Bodies[i]); //get gravity calculation result GetComponent <Rigidbody>().AddRelativeForce(currentGrav.GetForce()); //apply gravimetric force if (GetComponent <Atmospherics>()) { GetComponent <Atmospherics>().ApplyDragDueToGravity(currentGrav); //call for atmospheric drag to be applied } } } }