| | | 1 | | using UnityEngine; |
| | | 2 | | |
| | | 3 | | // The launch planner outputs a launch plan. |
| | | 4 | | public struct LaunchPlan { |
| | | 5 | | // If true, the interceptor should be launched. |
| | 0 | 6 | | public bool ShouldLaunch { get; init; } |
| | | 7 | | |
| | | 8 | | // Launch angle in degrees measured from the horizon. |
| | 0 | 9 | | public float LaunchAngle { get; init; } |
| | | 10 | | |
| | | 11 | | // Absolute intercept position. |
| | 0 | 12 | | public Vector3 InterceptPosition { get; init; } |
| | | 13 | | |
| | | 14 | | // No-launch launch plan. |
| | 0 | 15 | | public static LaunchPlan NoLaunch() { |
| | 0 | 16 | | return new LaunchPlan { ShouldLaunch = false }; |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | // Get the normalized launch vector given the agent's position. |
| | 0 | 20 | | public Vector3 NormalizedLaunchVector(in Vector3 position) { |
| | 0 | 21 | | Vector3 relativeInterceptPosition = InterceptPosition - position; |
| | 0 | 22 | | Vector3 interceptDirection = |
| | | 23 | | Coordinates3.ConvertCartesianToSpherical(relativeInterceptPosition); |
| | 0 | 24 | | return Coordinates3.ConvertSphericalToCartesian(r: 1, azimuth: interceptDirection[1], |
| | | 25 | | elevation: LaunchAngle); |
| | 0 | 26 | | } |
| | | 27 | | } |