private void FixedUpdate() { Vector3 pointVelocity = body.GetPointVelocity(transform.position); Vector3 airVelocity = Vector3.zero; Vector3 localFlow = transform.InverseTransformDirection(airVelocity - pointVelocity); airSpeed = -localFlow.z; airDensity = AirDensitySetting.getDensity(transform.position.y);//1.225f rpm = maxRPM * throttle; float rotationSpeed = rpm / 30 * Mathf.PI; //suppose rpm is large enough so aoa is small enough that outflow speend is just geometricalSpeed //also suppose geometricalSpeed = rpm / 60 * pitch; float area = Mathf.PI * diameter * diameter / 4; thrust = airDensity * area * 2 * geometricalSpeed * (geometricalSpeed - airSpeed); //thrust can be lesser than zero dragTorque = thrust * pitch / (2 * Mathf.PI) / propellerEfficiency * -rotationDirection * dragTorqueCoefficient; Vector3 angularMomentum = rotationSpeed * propellerInertia * rotationDirection * transform.forward; Vector3 precessionTorqueVector = -Vector3.Cross(body.angularVelocity, angularMomentum); precessionTorque = precessionTorqueVector.magnitude; Vector3 totalTorque = precessionTorqueVector + dragTorque * transform.forward; body.AddForceAtPosition(transform.forward * thrust, transform.position); body.AddTorque(totalTorque); }
private void FixedUpdate() { Vector3 foilVelocity = body.GetPointVelocity(transform.position); Vector3 airVelocity = Vector3.zero; Vector3 localFlow = transform.InverseTransformDirection(airVelocity - foilVelocity); localFlow.x = 0; planarFlowSpeed = localFlow.magnitude; float planarFlowSpeed1 = Mathf.Clamp(planarFlowSpeed, 0, maxSpeed); angleOfAttack = planarFlowSpeed > 0 ? -Mathf.Atan2(-localFlow.y, -localFlow.z) * Mathf.Rad2Deg : 0; airDensity = AirDensitySetting.getDensity(transform.position.y);//1.225f //float coeff1 = 0.5f * airDensity * planarFlowSpeed * planarFlowSpeed * chordLength*sectionLength; float coeff2 = 0.5f * airDensity * planarFlowSpeed1 * planarFlowSpeed1 * chordLength * sectionLength; drag = dragCoefficient.Evaluate(angleOfAttack) * coeff2; lift = liftCoefficient.Evaluate(angleOfAttack) * coeff2; Vector3 localForce = Quaternion.Euler(angleOfAttack, 0, 0) * new Vector3(0, lift, -drag); force = transform.TransformDirection(localForce); force = oldForce = Vector3.Lerp(oldForce, force, Time.fixedDeltaTime / (damping + Time.fixedDeltaTime)); body.AddForceAtPosition(force, transform.position); Debug.DrawRay(transform.position, transform.TransformDirection(localFlow).normalized, Color.blue); Debug.DrawRay(transform.position, transform.TransformDirection(localForce), Color.green); Debug.DrawRay(body.position, body.velocity.normalized, Color.red); }
public static float getDensity(float height) { if (!singleton) { var go = new GameObject("AirDensitySetting"); singleton = go.AddComponent <AirDensitySetting>(); } return(Mathf.Min(singleton.maxDensity, singleton.seaLevelDensity * Mathf.Pow(0.5f, height / singleton.halfDensityHeight))); }
private void Start() { singleton = this; }