@ -53,17 +53,28 @@ namespace Aerostats
// replace mesh and collider by a sphere (hack until proper assets are created)
var sphere = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
gameObject . GetComponentInChildren < MeshFilter > ( ) . mesh = sphere . GetComponent < MeshFilter > ( ) . mesh ;
Destroy ( gameObject . collider ) ;
var collider = gameObject . AddComponent < SphereCollider > ( ) ;
collider . radius = 0.67f ; // don't ask me, I don't know why
var meshFilter = gameObject . GetComponentInChildren < MeshFilter > ( ) ;
meshFilter . mesh = sphere . GetComponent < MeshFilter > ( ) . mesh ;
var t = meshFilter . transform ;
while ( t ! = transform )
{
t . localPosition = new Vector3 ( 0 , 0 , 0 ) ;
t . localRotation = Quaternion . identity ;
t . localScale = new Vector3 ( 1 , 1 , 1 ) ;
t = t . parent ;
}
var colliderObject = part . collider . gameObject ;
Destroy ( colliderObject . collider ) ;
var collider = colliderObject . AddComponent < SphereCollider > ( ) ;
collider . radius = 0.5f ;
Destroy ( sphere ) ;
gameObject . AddComponent < Rigidbody > ( ) ;
rigidbody . mass = EmptyMass * 0.001f ;
rigidbody . velocity = initialVelocity ; // start with the same velocity or everything explodes when deploying from a moving vessel
rigidbody . angularDrag = 1 0.0f ;
part . mass = rigidbody . mass ;
rigidbody . velocity = initialVelocity ;
rigidbody . position = transform . position ;
part . rb = rigidbody ;
InjectGas ( initialGasQuantity ) ;
@ -108,7 +119,7 @@ namespace Aerostats
CelestialBody body = vessel . mainBody ;
float externalTemperature = ( float ) FlightGlobals . getExternalTemperature ( worldPos , body ) ;
float balloonInternalTemperature = externalTemperature ;
float balloonInternalTemperature = Mathf . Max ( externalTemperature , 2 0.0f ) ;
float externalPressure = Math . Max ( ( float ) FlightGlobals . getStaticPressure ( worldPos , body ) * 1 0 0 0.0f , 0.00001f ) ;
float currentGasMoles = GasUtilities . StpVolumeToMoles * LiftingGasQuantity ;
@ -124,9 +135,15 @@ namespace Aerostats
// V = 4/3*pi*r^3
Radius = Mathf . Pow ( CurrentVolume * 0.75f / Mathf . PI , 0.333f ) ;
float scale = Radius + 0.1f ;
float scale = Mathf . Max ( Radius * 2.0f , 0.1f ) ;
if ( AttachedCase ! = null )
{
float dist = Vector3 . Distance ( AttachedCase . transform . position , transform . position ) ;
scale = Mathf . Min ( Mathf . Max ( dist , transform . localScale . x * 0.5f ) - 0.005f , scale * 0.5f ) * 2.0f ; // to prevent physics explosion due to interpenetration of objects, don't scale the balloon more than the space available between the case and the balloon (this happens when expanding fast after deploy in vaccum for example)
}
transform . localScale = new Vector3 ( scale , scale , scale ) ;
rigidbody . mass = ( EmptyMass + balloonGasMass ) * 0.001f ;
part . mass = rigidbody . mass ;
return LiftingGasQuantity ;
}
@ -140,7 +157,7 @@ namespace Aerostats
CelestialBody body = vessel . mainBody ;
float externalTemperature = ( float ) FlightGlobals . getExternalTemperature ( worldPos , body ) ;
float balloonInternalTemperature = externalTemperature ;
float balloonInternalTemperature = Mathf . Max ( externalTemperature , 2 0.0f ) ;
float externalPressure = Math . Max ( ( float ) FlightGlobals . getStaticPressure ( worldPos , body ) * 1 0 0 0.0f , 0.00001f ) ;
Util . PostDebugSingleScreenMessage ( "external atmo" , "Temperature = " + externalTemperature + "K, Pressure=" + externalPressure + "Pa" ) ;
@ -158,14 +175,18 @@ namespace Aerostats
InjectGas ( 0 ) ; // update security valve venting
var gravityAccel = FlightGlobals . getGeeForceAtPosition ( worldPos ) ;
var gravityAccel = FlightGlobals . getGeeForceAtPosition ( rigidbody . position ) ;
//Util.PostSingleScreenMessage("gravity", "Gravity accel = (" + gravityAccel.x + ", " + gravityAccel.y + ", " + gravityAccel.z + ")");
float externalTemperature = ( float ) FlightGlobals . getExternalTemperature ( worldPos , body ) ;
float balloonInternalTemperature = externalTemperature ;
float externalPressure = Math . Max ( ( float ) FlightGlobals . getStaticPressure ( worldPos , body ) * 1 0 0 0.0f , 0.00001f ) ;
float externalPressure = ( float ) FlightGlobals . getStaticPressure ( worldPos , body ) * 1 0 0 0.0f ;
float airDensity = ( float ) FlightGlobals . getAtmDensity ( externalPressure / 1 0 0 0.0f , externalTemperature , body ) ;
rigidbody . angularDrag = Mathf . Max ( 0.5f , 1 0.0f * externalPressure / GasUtilities . StandardPressure ) ;
if ( externalPressure > 0.00001f )
{
// lift
rigidbody . AddForce ( - gravityAccel * Lift / 1 0 0 0.0f , ForceMode . Force ) ;
// balloon drag
@ -177,4 +198,5 @@ namespace Aerostats
rigidbody . AddForce ( - airVelocity . normalized * dragForce / 1 0 0 0.0f , ForceMode . Force ) ;
}
}
}
}