| | | 1 | | using UnityEngine; |
| | | 2 | | |
| | | 3 | | // Aerial movement. |
| | | 4 | | // |
| | | 5 | | // Interceptors and threats have different movements since threats are not affected by drag and |
| | | 6 | | // gravity and have specified attack behaviors. |
| | | 7 | | public abstract class AerialMovement : MovementBase { |
| | 45 | 8 | | public AerialMovement(IAgent agent) : base(agent) {} |
| | | 9 | | |
| | | 10 | | // Calculate the dynamic pressure on the agent. |
| | 10 | 11 | | protected float GetDynamicPressure() { |
| | 10 | 12 | | float airDensity = Constants.CalculateAirDensityAtAltitude(Agent.Position.y); |
| | 10 | 13 | | float flowSpeed = Agent.Speed; |
| | 10 | 14 | | return 0.5f * airDensity * (flowSpeed * flowSpeed); |
| | 10 | 15 | | } |
| | | 16 | | |
| | | 17 | | // Calculate the air drag acting on the agent. |
| | 10 | 18 | | protected float CalculateDrag() { |
| | 10 | 19 | | var staticConfig = Agent.StaticConfig; |
| | 10 | 20 | | float dragCoefficient = staticConfig.LiftDragConfig?.DragCoefficient ?? 0; |
| | 10 | 21 | | float crossSectionalArea = staticConfig.BodyConfig?.CrossSectionalArea ?? 0; |
| | 10 | 22 | | float mass = staticConfig.BodyConfig?.Mass ?? 1; |
| | 10 | 23 | | float dynamicPressure = GetDynamicPressure(); |
| | 10 | 24 | | float dragForce = dragCoefficient * dynamicPressure * crossSectionalArea; |
| | 10 | 25 | | return dragForce / mass; |
| | 10 | 26 | | } |
| | | 27 | | |
| | | 28 | | // Calculate the lift-induced drag acting on the agent. Since the agent is flying, any |
| | | 29 | | // acceleration normal to the velocity vector is considered "lift". |
| | 10 | 30 | | protected float CalculateLiftInducedDrag(in Vector3 accelerationInput) { |
| | 10 | 31 | | var staticConfig = Agent.StaticConfig; |
| | 10 | 32 | | float liftAcceleration = Vector3.ProjectOnPlane(accelerationInput, Agent.Forward).magnitude; |
| | 10 | 33 | | float liftDragRatio = staticConfig.LiftDragConfig?.LiftDragRatio ?? 1; |
| | 10 | 34 | | return Mathf.Abs(liftAcceleration / liftDragRatio); |
| | 10 | 35 | | } |
| | | 36 | | } |