# Wingsuit & Glider Aerodynamics, Energy Diving, Coordinated Banking & Updrafts in Unity 6

> Energy-conserving wingsuit and glider flight physics in Unity 6: lift-and-drag polar curves by angle of attack, diving-to-speed conversion, roll-coupled yaw banking, ridge updraft thermals, stall recovery, and dynamic speed-reactive chase camera framing.

- **Canonical page:** https://gamecrew.ai/techniques/unity/flight-wingsuit-aerodynamics
- **Techniques hub:** https://gamecrew.ai/techniques
- **Engine:** Unity 6
- **Category:** physics
- **Tags:** `flight`, `wingsuit`, `glider`, `airplane`, `aerodynamics`, `lift`, `drag`, `banking`, `thermal`, `dive`, `soar`, `physics`, `camera`
- **Verification:** Compile-verified pattern
- **Revision:** 1 (2026-11-30)
- **Demo:** No demo

## When to Use (and When Not To)

Use lift-and-drag polar flight physics for wingsuit cliff-diving, ridge soaring, alpine glider runs, bush-plane island deliveries, and aerial ring challenges where trading altitude for airspeed, carving banked turns through narrow fjords, and pulling out of dives feel exhilarating and predictable.

Skip full aerodynamic lift integration for hovering quadcopter drones or arcadey top-down shooters where direct velocity steering is cleaner.

## Mathematical & Algorithmic Core

1. **Angle of Attack & Glide Polar**: Let $\mathbf{v}$ be world velocity (speed $v = \|\mathbf{v}\|$) and $\hat{\mathbf{f}}, \hat{\mathbf{u}}$ be the body's forward and up axes. Compute local pitch angle of attack $\alpha = \operatorname{atan2}(-\mathbf{v}\cdot\hat{\mathbf{u}},\; \mathbf{v}\cdot\hat{\mathbf{f}})$:
   - Lift coefficient $C_L(\alpha) \approx C_{L0} + k_L \sin(2\alpha)$ (peaks near $\alpha \approx 18^\circ$ and softens gently past stall instead of snapping violently).
   - Induced + parasitic drag $C_D(\alpha) = C_{D0} + k_D C_L(\alpha)^2$.
   - Dynamic pressure $q = \frac{1}{2}\rho v^2 S$:
     $$\mathbf{F}_{\text{lift}} = q\,C_L(\alpha)\,\hat{\mathbf{u}}_{\perp}, \qquad \mathbf{F}_{\text{drag}} = -q\,C_D(\alpha)\,\hat{\mathbf{v}}$$
2. **Coordinated Roll-to-Yaw Banking**: Rolling by bank angle $\phi \in [-65^\circ, 65^\circ]$ turns the nose smoothly around world up at $\dot{\psi} = k_{\text{turn}}\,\sin(\phi)$ while aligning velocity toward $\hat{\mathbf{f}}$ so turns carve wide, graceful arcs without sideslipping straight into canyon walls.
3. **Ridge Updrafts & Speed Feedback**: Add vertical thermal air velocity $\mathbf{v}_{\text{wind}}$ inside trigger volumes over sunlit cliff faces so players can climb back up after a close-proximity buzz. Drive chase camera FOV (`62° → 82°`), wind-rush audio volume/pitch, and wingtip trail opacity from normalized airspeed $v / v_{\max}$.

## Engine Implementation

### Wingsuit & Glider Aerodynamics Controller (`Assets/Game/Runtime/Flight/WingsuitFlightController.cs`)

```csharp
using CCGD;
using UnityEngine;

namespace Game.Flight
{
    public sealed class WingsuitFlightController : MonoBehaviour
    {
        [Header("Aerodynamic Tuning")]
        public float MinAirspeed = 14f;
        public float CruiseAirspeed = 32f;
        public float MaxAirspeed = 68f;
        public float Gravity = 15.5f;
        public float LiftStrength = 0.017f;
        public float BaseDrag = 0.0022f;
        public float InducedDrag = 0.0065f;

        [Header("Attitude & Banking")]
        public float PitchRateDeg = 68f;
        public float RollRateDeg = 115f;
        public float MaxPitchUpDeg = 32f;
        public float MaxPitchDownDeg = -62f;
        public float MaxBankDeg = 62f;
        public float BankTurnRateDeg = 58f;
        public float VelocityAlignRate = 2.8f;

        public Vector3 Velocity { get; private set; }
        public float Airspeed => Velocity.magnitude;
        public float NormalizedSpeed => Mathf.InverseLerp(MinAirspeed, MaxAirspeed, Airspeed);
        public float BankDeg { get; private set; }
        public float PitchDeg { get; private set; }
        public float YawDeg { get; private set; }

        Vector3 externalWind;

        public void Launch(Vector3 startPos, float startYawDeg, float initialSpeed = 28f)
        {
            transform.position = startPos;
            YawDeg = startYawDeg;
            PitchDeg = -10f;
            BankDeg = 0f;
            transform.rotation = Quaternion.Euler(PitchDeg, YawDeg, 0f);
            Velocity = transform.forward * initialSpeed;
        }

        public void SetExternalWind(Vector3 windVelocity) => externalWind = windVelocity;

        void Start()
        {
            if (Velocity.sqrMagnitude < 1f)
                Launch(transform.position, transform.eulerAngles.y, CruiseAirspeed);
        }

        void Update()
        {
            float dt = Mathf.Clamp(Time.deltaTime, 0.001f, 0.05f);
            Vector2 stick = GameInput.Move;

            // Pitch control (push forward to dive and build speed; pull back to flare and gain lift).
            float targetPitchDelta = -stick.y * PitchRateDeg * dt;
            PitchDeg = Mathf.Clamp(PitchDeg + targetPitchDelta, MaxPitchDownDeg, MaxPitchUpDeg);

            // Soft stall nudge: if airspeed gets low while pitched up, gently lower the nose.
            if (Airspeed < MinAirspeed + 4f && PitchDeg > -4f)
                PitchDeg = Mathf.MoveTowards(PitchDeg, -14f, 35f * dt);

            // Roll control with gentle self-leveling when stick is neutral.
            float targetBank = -stick.x * MaxBankDeg;
            BankDeg = Mathf.MoveTowards(BankDeg, targetBank, RollRateDeg * dt);

            // Coordinated turn rate coupled to bank angle.
            float bankRad = BankDeg * Mathf.Deg2Rad;
            YawDeg -= Mathf.Sin(bankRad) * BankTurnRateDeg * dt;

            transform.rotation = Quaternion.Euler(PitchDeg, YawDeg, BankDeg);

            // Aerodynamic forces relative to airmass (including ridge updrafts).
            Vector3 relVel = Velocity - externalWind;
            float speed = Mathf.Max(1f, relVel.magnitude);
            Vector3 velDir = relVel / speed;

            float aoa = Mathf.Atan2(-Vector3.Dot(relVel, transform.up), Mathf.Max(0.5f, Vector3.Dot(relVel, transform.forward)));
            float cl = Mathf.Clamp(0.45f + 1.35f * Mathf.Sin(2f * aoa), -0.3f, 1.35f);
            float cd = BaseDrag + InducedDrag * cl * cl;

            Vector3 liftDir = Vector3.Cross(Vector3.Cross(velDir, transform.up), velDir).normalized;
            if (liftDir.sqrMagnitude < 0.01f) liftDir = transform.up;

            Vector3 accel = Vector3.down * Gravity;
            accel += liftDir * (speed * speed * LiftStrength * cl);
            accel -= velDir * (speed * speed * cd);

            Velocity += accel * dt;

            // Blend velocity direction smoothly toward nose so banking carves predictably.
            float postSpeed = Mathf.Clamp(Velocity.magnitude, MinAirspeed, MaxAirspeed);
            Vector3 alignedDir = Vector3.Slerp(Velocity.normalized, transform.forward, 1f - Mathf.Exp(-VelocityAlignRate * dt));
            Velocity = alignedDir * postSpeed;

            transform.position += Velocity * dt;
        }
    }
}
```

## Performance & Platform Traps

- **Far-Clip & Horizon Depth**: Alpine fjords and flight islands need `Camera.farClipPlane = 1200–2500 m` paired with smooth exponential height/distance fog (`atmospheric-lighting-fog`) so distant peaks dissolve gracefully instead of clipping into hard polygons.
- **No VR Camera Roll**: If running in VR (`GameXR.Active`), keep `GameXR.Rig` level on the horizon and bank only the visual wingsuit/cockpit mesh around the player.
- **Proximity Collision Recovery**: Use a generous sphere sweep ahead of `transform.position` so cliff grazes trigger an exciting scrape spark + bounce or clean checkpoint reset instead of tunneling through thin terrain faces.

## Verification Checklist

1. In PlayMode, dive (`stick.y > 0`) for 2 seconds and assert `Airspeed` rises above `CruiseAirspeed`, then flare (`stick.y < 0`) and confirm altitude climb + gentle stall recovery.
2. Bank right (`stick.x > 0`) for 1.5 seconds and confirm `YawDeg` turns smoothly right without spinning out.
3. Verify mountain vista captures show clear valley guidance rings, horizon haze, and clean speed HUD framing.

## Official references

- NASA Glenn Beginner's Guide to Aerodynamics (Lift & Drag Polars)
- Steep / Superflight Glide-Ratio & Banking Feel Architecture
- Unity 6 FixedUpdate Flight Dynamics
