private Vector3d BuoyantDragForce(Rigidbody body, double depthFactor) { float tmp = 0; if (depthFactor < 0.5) { tmp += (float)depthFactor * 2f; //drag from depth } else { tmp += (float)(1f - depthFactor) * 2f; } Vector3d dragForce = Vector3.Project(body.velocity, vessel.upAxis); double vertVel = dragForce.magnitude; dragForce *= vertVel; dragForce *= tmp * BBPlanetOceanDensity.EvaluateBodyOceanDensity(vessel.mainBody); if (dragForce.magnitude * TimeWarp.fixedDeltaTime / body.mass > vertVel) { dragForce = vessel.upAxis * vertVel; } return(-dragForce); }
private Vector3d BuoyancyForce(Rigidbody body, double depth) { ApplySplashEffect(depth, body); if (CheckDieOnHighVelocity(body)) { return(Vector3.zero); } double vol; double depthForMaxForce; if (overrideVol > 0) { vol = overrideVol; depthForMaxForce = overridedepthForMaxForce; } else if (part.collider) { Vector3 size = part.collider.bounds.size; vol = size.magnitude; //This is highly approximate, but it works depthForMaxForce = Math.Max(Math.Max(size.x, Math.Max(size.y, size.z)), 2); //This is a very, very rough model of partial immersion } else { vol = 1; depthForMaxForce = 2; } double depthFactor = depth / depthForMaxForce; depthFactor = Math.Min(depthFactor, 1); part.rigidbody.drag = 3 * (float)depthFactor; Vector3d gForce = -FlightGlobals.getGeeForceAtPosition(part.transform.position); Vector3d buoyancyForce = gForce * depthFactor; buoyancyForce *= vol * BBPlanetOceanDensity.EvaluateBodyOceanDensity(vessel.mainBody); if (buoyancyForce.sqrMagnitude > part.mass * gForce.sqrMagnitude * 1.5) { buoyancyForce = part.mass * gForce * 1.5; } return(buoyancyForce); }
private Vector3d BuoyancyForce(Rigidbody body, double depth) { if (CheckDieOnHighVelocity(body)) { return(Vector3.zero); } Vector3d gForce = -FlightGlobals.getGeeForceAtPosition(part.transform.position); Vector3d buoyancyForce = gForce * depthFactor; buoyancyForce *= volume * BBPlanetOceanDensity.EvaluateBodyOceanDensity(vessel.mainBody); return(buoyancyForce); }