start on new threat types & strategy abstraction

more-targets
turtlebasket 2024-09-29 15:52:09 -07:00
parent 07ad59a5f1
commit 9a7c51c907
22 changed files with 824 additions and 196 deletions

View File

@ -287,10 +287,10 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 8462434346230391091} - component: {fileID: 8462434346230391091}
- component: {fileID: 4571646124809534626}
- component: {fileID: 4451965530778273955} - component: {fileID: 4451965530778273955}
- component: {fileID: 4194966225731047199}
m_Layer: 0 m_Layer: 0
m_Name: MissileThreat m_Name: FixedWingMissileThreat
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -314,24 +314,6 @@ Transform:
- {fileID: 9192475791974545516} - {fileID: 9192475791974545516}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &4571646124809534626
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6438458936967544359}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f532f6ee629e87643b7b75a50e83083f, type: 3}
m_Name:
m_EditorClassIdentifier:
_flightPhase: 0
_velocity: {x: 0, y: 0, z: 0}
_acceleration: {x: 0, y: 0, z: 0}
_dragAcceleration: {x: 0, y: 0, z: 0}
_target: {fileID: 0}
staticConfigFile: drone.json
--- !u!54 &4451965530778273955 --- !u!54 &4451965530778273955
Rigidbody: Rigidbody:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -359,3 +341,21 @@ Rigidbody:
m_Interpolate: 0 m_Interpolate: 0
m_Constraints: 0 m_Constraints: 0
m_CollisionDetection: 0 m_CollisionDetection: 0
--- !u!114 &4194966225731047199
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6438458936967544359}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e6c2fbd1e492be448760f5045b13b2e, type: 3}
m_Name:
m_EditorClassIdentifier:
_flightPhase: 3
_velocity: {x: 0, y: 0, z: 0}
_acceleration: {x: 0, y: 0, z: 0}
_dragAcceleration: {x: 0, y: 0, z: 0}
_target: {fileID: 0}
staticConfigFile: generic_static_config.json

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9c1ccc1cc7ad8cb4aa0b59a0afd50568
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,361 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &295999596028346972
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 9192475791974545516}
- component: {fileID: 3681380462727606042}
- component: {fileID: 5038767565634652910}
m_Layer: 0
m_Name: Cone
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &9192475791974545516
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 295999596028346972}
serializedVersion: 2
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
m_LocalPosition: {x: 0, y: 0, z: -3.89}
m_LocalScale: {x: 20, y: 20, z: 20}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8462434346230391091}
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!33 &3681380462727606042
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 295999596028346972}
m_Mesh: {fileID: 4300000, guid: 36b72d5a34c22d94c88a068dfcbdf27a, type: 2}
--- !u!23 &5038767565634652910
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 295999596028346972}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 061083197c659dc44983633a84d39cea, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!1 &4390675743535140416
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 585396986125101381}
- component: {fileID: 4620404264009677289}
m_Layer: 0
m_Name: TrailRenderer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &585396986125101381
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4390675743535140416}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 10, y: 10, z: 10}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8462434346230391091}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!96 &4620404264009677289
TrailRenderer:
serializedVersion: 3
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4390675743535140416}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 0
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 0e42500808910f24cb6626a81760c995, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Time: 5
m_PreviewTimeScale: 1
m_Parameters:
serializedVersion: 3
widthMultiplier: 5
widthCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
colorGradient:
serializedVersion: 2
key0: {r: 1, g: 0, b: 0, a: 1}
key1: {r: 1, g: 1, b: 1, a: 1}
key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 0
ctime3: 0
ctime4: 0
ctime5: 0
ctime6: 0
ctime7: 0
atime0: 0
atime1: 65535
atime2: 0
atime3: 0
atime4: 0
atime5: 0
atime6: 0
atime7: 0
m_Mode: 0
m_ColorSpace: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 2
numCornerVertices: 0
numCapVertices: 0
alignment: 0
textureMode: 0
textureScale: {x: 1, y: 1}
shadowBias: 0.5
generateLightingData: 0
m_MinVertexDistance: 0.1
m_MaskInteraction: 0
m_Autodestruct: 0
m_Emitting: 1
m_ApplyActiveColorSpace: 0
--- !u!1 &4590233640347492898
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8315564871113561163}
- component: {fileID: 6203868598056538240}
m_Layer: 0
m_Name: Collider
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8315564871113561163
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4590233640347492898}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8462434346230391091}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!135 &6203868598056538240
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4590233640347492898}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Radius: 10
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &6438458936967544359
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8462434346230391091}
- component: {fileID: -2759790757235477429}
- component: {fileID: 4451965530778273955}
m_Layer: 0
m_Name: RollStabilizedMissileThreat
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8462434346230391091
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6438458936967544359}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 585396986125101381}
- {fileID: 8315564871113561163}
- {fileID: 9192475791974545516}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &-2759790757235477429
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6438458936967544359}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 16e40584b2154ef4a95c84e85a321999, type: 3}
m_Name:
m_EditorClassIdentifier:
_flightPhase: 3
_velocity: {x: 0, y: 0, z: 0}
_acceleration: {x: 0, y: 0, z: 0}
_dragAcceleration: {x: 0, y: 0, z: 0}
_target: {fileID: 0}
staticConfigFile: base_roll_stabilized_missile.json
--- !u!54 &4451965530778273955
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6438458936967544359}
serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_ImplicitCom: 1
m_ImplicitTensor: 1
m_UseGravity: 0
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0

View File

@ -128,6 +128,10 @@ public abstract class Agent : MonoBehaviour {
return GetComponent<Rigidbody>().linearVelocity; return GetComponent<Rigidbody>().linearVelocity;
} }
public Vector3 GetAcceleration() {
return _acceleration;
}
public double GetDynamicPressure() { public double GetDynamicPressure() {
var airDensity = Constants.CalculateAirDensityAtAltitude(transform.position.y); var airDensity = Constants.CalculateAirDensityAtAltitude(transform.position.y);
var flowSpeed = GetSpeed(); var flowSpeed = GetSpeed();

View File

@ -4,115 +4,121 @@ using UnityEngine;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
[Serializable] [Serializable]
public class SimulationConfig { public class SimulationConfig {
[Header("Simulation Settings")] [Header("Simulation Settings")]
public float timeScale = 0.05f; public float timeScale = 0.05f;
[Header("Interceptor Swarm Configurations")] // [Header("Defense Points")]
public List<SwarmConfig> interceptor_swarm_configs = new List<SwarmConfig>(); // public SwarmConfig defense_points_config;
[Header("Threat Swarm Configurations")] [Header("Interceptor Swarm Configurations")]
public List<SwarmConfig> threat_swarm_configs = new List<SwarmConfig>(); public List<SwarmConfig> interceptor_swarm_configs = new List<SwarmConfig>();
[Header("Threat Swarm Configurations")]
public List<SwarmConfig> threat_swarm_configs = new List<SwarmConfig>();
} }
[Serializable] [Serializable]
public class DynamicConfig { public class DynamicConfig {
public LaunchConfig launch_config; public LaunchConfig launch_config;
public SensorConfig sensor_config; public SensorConfig sensor_config;
} }
[Serializable] [Serializable]
public class SwarmConfig { public class SwarmConfig {
public int num_agents; public int num_agents;
public AgentConfig agent_config; public AgentConfig agent_config;
} }
[Serializable] [Serializable]
public class AgentConfig { public class AgentConfig {
public InterceptorType interceptor_type; public InterceptorType interceptor_type;
public ThreatType threat_type; public ThreatType threat_type;
public InitialState initial_state; public InitialState initial_state;
public StandardDeviation standard_deviation; public StandardDeviation standard_deviation;
public DynamicConfig dynamic_config; public DynamicConfig dynamic_config;
public PlottingConfig plotting_config; public PlottingConfig plotting_config;
public SubmunitionsConfig submunitions_config; public SubmunitionsConfig submunitions_config;
public static AgentConfig FromSubmunitionAgentConfig(SubmunitionAgentConfig submunitionConfig) { public static AgentConfig FromSubmunitionAgentConfig(SubmunitionAgentConfig submunitionConfig) {
return new AgentConfig { return new AgentConfig {
interceptor_type = submunitionConfig.interceptor_type, interceptor_type = submunitionConfig.interceptor_type,
initial_state = submunitionConfig.initial_state, initial_state = submunitionConfig.initial_state,
standard_deviation = submunitionConfig.standard_deviation, standard_deviation = submunitionConfig.standard_deviation,
dynamic_config = submunitionConfig.dynamic_config, dynamic_config = submunitionConfig.dynamic_config,
plotting_config = submunitionConfig.plotting_config, plotting_config = submunitionConfig.plotting_config,
// Set other fields as needed, using default values if not present in SubmunitionAgentConfig // Set other fields as needed, using default values if not present in SubmunitionAgentConfig
threat_type = ThreatType.DRONE, // Or another default value threat_type = ThreatType.DRONE, // Or another default value
submunitions_config = null // Or a default value if needed submunitions_config = null // Or a default value if needed
}; };
} }
} }
[Serializable] [Serializable]
public class InitialState { public class InitialState {
public Vector3 position; public Vector3 position;
public Vector3 rotation; public Vector3 rotation;
public Vector3 velocity; public Vector3 velocity;
} }
[Serializable] [Serializable]
public class StandardDeviation { public class StandardDeviation {
public Vector3 position; public Vector3 position;
public Vector3 velocity; public Vector3 velocity;
} }
[Serializable] [Serializable]
public class LaunchConfig { public class LaunchConfig {
public float launch_time; public float launch_time;
} }
[Serializable] [Serializable]
public class PlottingConfig { public class PlottingConfig {
public ConfigColor color; public ConfigColor color;
public LineStyle linestyle; public LineStyle linestyle;
public Marker marker; public Marker marker;
} }
[Serializable] [Serializable]
public class SubmunitionsConfig { public class SubmunitionsConfig {
public int num_submunitions; public int num_submunitions;
public LaunchConfig launch_config; public LaunchConfig launch_config;
public SubmunitionAgentConfig agent_config; public SubmunitionAgentConfig agent_config;
} }
[Serializable] [Serializable]
public class SubmunitionAgentConfig { public class SubmunitionAgentConfig {
public InterceptorType interceptor_type; public InterceptorType interceptor_type;
public InitialState initial_state; public InitialState initial_state;
public StandardDeviation standard_deviation; public StandardDeviation standard_deviation;
public DynamicConfig dynamic_config; public DynamicConfig dynamic_config;
public PlottingConfig plotting_config; public PlottingConfig plotting_config;
} }
[Serializable] [Serializable]
public class SensorConfig { public class SensorConfig {
public SensorType type; public SensorType type;
public float frequency; public float frequency;
} }
[Serializable] [Serializable]
public class TargetConfig { public class TargetConfig {
public ThreatType threat_type; public ThreatType threat_type;
public InitialState initial_state; public InitialState initial_state;
public PlottingConfig plotting_config; public PlottingConfig plotting_config;
public string prefabName; public string prefabName;
} }
// Enums // Enums
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public enum InterceptorType { HYDRA_70, MICROMISSILE } public enum InterceptorType { HYDRA_70, MICROMISSILE }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public enum ThreatType { DRONE, MISSILE } public enum ThreatType {
DRONE,
FIXED_WING_MISSILE,
ROLL_STABILIZED_MISSILE
} // Add ballistic later -michael
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public enum ConfigColor { BLUE, GREEN, RED } public enum ConfigColor { BLUE, GREEN, RED }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]

View File

@ -0,0 +1,28 @@
using UnityEngine;
/// <summary>
/// Static targetable point to defend
/// </summary>
public class DefendPoint : Agent {
// Currently just initializes to the origin
public DefendPoint() {
// Set the initial state
this.transform.position = Vector3.zero;
}
protected override void FixedUpdate() {
return;
}
protected override void UpdateBoost(double deltaTime) {
return;
}
protected override void UpdateMidCourse(double deltaTime) {
return;
}
protected override void UpdateReady(double deltaTime) {
return;
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7eed014a152a65043be19cd044faa5d2

View File

@ -75,7 +75,6 @@ public class SimManager : MonoBehaviour {
StartSimulation(); StartSimulation();
ResumeSimulation(); ResumeSimulation();
} }
} }
public void SetTimeScale(float timeScale) { public void SetTimeScale(float timeScale) {
@ -197,9 +196,10 @@ public class SimManager : MonoBehaviour {
/// <param name="config">Configuration settings for the interceptor.</param> /// <param name="config">Configuration settings for the interceptor.</param>
/// <returns>The created Interceptor instance, or null if creation failed.</returns> /// <returns>The created Interceptor instance, or null if creation failed.</returns>
public Interceptor CreateInterceptor(AgentConfig config) { public Interceptor CreateInterceptor(AgentConfig config) {
string prefabName = config.interceptor_type switch { InterceptorType.HYDRA_70 => "Hydra70", string prefabName =
InterceptorType.MICROMISSILE => "Micromissile", config.interceptor_type switch { InterceptorType.HYDRA_70 => "Hydra70",
_ => "Hydra70" }; InterceptorType.MICROMISSILE => "Micromissile",
_ => "Hydra70" };
GameObject missileObject = CreateAgent(config, prefabName); GameObject missileObject = CreateAgent(config, prefabName);
if (missileObject == null) if (missileObject == null)
@ -231,7 +231,8 @@ public class SimManager : MonoBehaviour {
/// <returns>The created Threat instance, or null if creation failed.</returns> /// <returns>The created Threat instance, or null if creation failed.</returns>
private Threat CreateThreat(AgentConfig config) { private Threat CreateThreat(AgentConfig config) {
string prefabName = config.threat_type switch { string prefabName = config.threat_type switch {
ThreatType.DRONE => "Drone", ThreatType.MISSILE => "MissileThreat", ThreatType.DRONE => "Drone", ThreatType.FIXED_WING_MISSILE => "FixedWingMissileThreat",
ThreatType.ROLL_STABILIZED_MISSILE => "RollStabilizedMissileThreat",
_ => throw new System.ArgumentException($"Unsupported threat type: {config.threat_type}") _ => throw new System.ArgumentException($"Unsupported threat type: {config.threat_type}")
}; };
GameObject threatObject = CreateAgent(config, prefabName); GameObject threatObject = CreateAgent(config, prefabName);

View File

@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class DroneTarget : Threat { public class DroneThreat : Threat {
// Start is called before the first frame update // Start is called before the first frame update
protected override void Start() { protected override void Start() {
base.Start(); base.Start();

View File

@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FixedWingMissileThreat : Threat {
protected override void UpdateBoost(double deltaTime) {
throw new System.NotImplementedException();
}
protected override void UpdateMidCourse(double deltaTime) {
throw new System.NotImplementedException();
}
/// <summary>
/// Strategy for moving the Threat in a straight path towards its target.
/// </summary>
public class DirectPathStrategy : NavigationStrategy {
public override void Execute(Threat threat, List<Threat> swarmMates, FlightPhase flightPhase,
List<Interceptor> interceptors, double deltaTime) {
throw new System.NotImplementedException();
}
}
/// <summary>
/// Strategy for moving the Threat in an S-curve towards a predefined target.
/// </summary>
public class SlalomStrategy : NavigationStrategy {
private float maxAmplitude;
private float periodDistance;
public SlalomStrategy(float maxAmplitude, float periodDistance) {
this.maxAmplitude = maxAmplitude;
this.periodDistance = periodDistance;
}
public override void Execute(Threat threat, List<Threat> swarmMates, FlightPhase flightPhase,
List<Interceptor> interceptors, double deltaTime) {
throw new System.NotImplementedException();
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4e6c2fbd1e492be448760f5045b13b2e

View File

@ -1,107 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Base class for missile targets. Uses same set of flight phases as base Hydra-70.
/// </summary>
public class MissileThreat : Threat
{
protected float boostAcceleration = 20;
protected float midcourseAcceleration = 5;
protected override void UpdateReady(double deltaTime)
{
// if in ready phase, just set to boost phase immediately
SetFlightPhase(FlightPhase.BOOST);
}
protected override void UpdateBoost(double deltaTime)
{
// The interceptor only accelerates along its roll axis (forward in Unity)
Vector3 rollAxis = transform.forward;
// Calculate boost acceleration
float boostAcceleration =
(float)(_staticConfig.boostConfig.boostAcceleration * Constants.kGravity);
Vector3 accelerationInput = boostAcceleration * rollAxis;
// Calculate the total acceleration
Vector3 acceleration = CalculateAcceleration(accelerationInput);
// Apply the acceleration force
GetComponent<Rigidbody>().AddForce(acceleration, ForceMode.Acceleration);
}
protected override void UpdateMidCourse(double deltaTime)
{
Vector3 accelerationInput = Vector3.zero;
// Calculate and set the total acceleration
Vector3 acceleration = CalculateAcceleration(accelerationInput);
GetComponent<Rigidbody>().AddForce(acceleration, ForceMode.Acceleration);
}
protected Vector3 CalculateAcceleration(Vector3 accelerationInput,
bool compensateForGravity = false)
{
Vector3 gravity = Physics.gravity;
if (compensateForGravity)
{
Vector3 gravityProjection = CalculateGravityProjectionOnPitchAndYaw();
accelerationInput -= gravityProjection;
}
float airDrag = CalculateDrag();
float liftInducedDrag = CalculateLiftInducedDrag(accelerationInput);
float dragAcceleration = -(airDrag + liftInducedDrag);
// Project the drag acceleration onto the forward direction
Vector3 dragAccelerationAlongRoll = dragAcceleration * transform.forward;
_dragAcceleration = dragAccelerationAlongRoll;
return accelerationInput + gravity + dragAccelerationAlongRoll;
}
protected float CalculateMaxAcceleration()
{
float maxReferenceAcceleration =
(float)(_staticConfig.accelerationConfig.maxReferenceAcceleration * Constants.kGravity);
float referenceSpeed = _staticConfig.accelerationConfig.referenceSpeed;
return Mathf.Pow(GetComponent<Rigidbody>().linearVelocity.magnitude / referenceSpeed, 2) *
maxReferenceAcceleration;
}
protected Vector3 CalculateGravityProjectionOnPitchAndYaw()
{
Vector3 gravity = Physics.gravity;
Vector3 pitchAxis = transform.right;
Vector3 yawAxis = transform.up;
// Project the gravity onto the pitch and yaw axes
float gravityProjectionPitchCoefficient = Vector3.Dot(gravity, pitchAxis);
float gravityProjectionYawCoefficient = Vector3.Dot(gravity, yawAxis);
// Return the sum of the projections
return gravityProjectionPitchCoefficient * pitchAxis +
gravityProjectionYawCoefficient * yawAxis;
}
private float CalculateDrag()
{
float dragCoefficient = _staticConfig.liftDragConfig.dragCoefficient;
float crossSectionalArea = _staticConfig.bodyConfig.crossSectionalArea;
float mass = _staticConfig.bodyConfig.mass;
float dynamicPressure = (float)GetDynamicPressure();
float dragForce = dragCoefficient * dynamicPressure * crossSectionalArea;
return dragForce / mass;
}
private float CalculateLiftInducedDrag(Vector3 accelerationInput)
{
float liftAcceleration =
(accelerationInput - Vector3.Dot(accelerationInput, transform.up) * transform.up).magnitude;
float liftDragRatio = _staticConfig.liftDragConfig.liftDragRatio;
return Mathf.Abs(liftAcceleration / liftDragRatio);
}
}

View File

@ -0,0 +1,204 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Base class for missile targets. Uses same set of flight phases as base Hydra-70.
/// </summary>
public class RollStabilizedMissileThreat : Threat {
protected float boostAcceleration = 20;
protected float midcourseAcceleration = 0;
protected float terminalAcceleration = 22;
protected float maxAmplitude = 22;
public RollStabilizedMissileThreat() {
strategy = new DirectPathStrategy();
}
protected override void UpdateBoost(double deltaTime) {
// The interceptor only accelerates along its roll axis (forward in Unity)
Vector3 rollAxis = transform.forward;
// Calculate boost acceleration
float boostAcceleration =
(float)(_staticConfig.boostConfig.boostAcceleration * Constants.kGravity);
Vector3 accelerationInput = boostAcceleration * rollAxis;
// Calculate the total acceleration
Vector3 acceleration = CalculateAcceleration(accelerationInput);
// Apply the acceleration force
GetComponent<Rigidbody>().AddForce(acceleration, ForceMode.Acceleration);
}
protected override void UpdateMidCourse(double deltaTime) {
Vector3 accelerationInput = Vector3.zero;
// Calculate and set the total acceleration
Vector3 acceleration = CalculateAcceleration(accelerationInput);
GetComponent<Rigidbody>().AddForce(acceleration, ForceMode.Acceleration);
}
protected Vector3 CalculateAcceleration(Vector3 accelerationInput,
bool compensateForGravity = false) {
Vector3 gravity = Physics.gravity;
if (compensateForGravity) {
Vector3 gravityProjection = CalculateGravityProjectionOnPitchAndYaw();
accelerationInput -= gravityProjection;
}
float airDrag = CalculateDrag();
float liftInducedDrag = CalculateLiftInducedDrag(accelerationInput);
float dragAcceleration = -(airDrag + liftInducedDrag);
// Project the drag acceleration onto the forward direction
Vector3 dragAccelerationAlongRoll = dragAcceleration * transform.forward;
_dragAcceleration = dragAccelerationAlongRoll;
return accelerationInput + gravity + dragAccelerationAlongRoll;
}
protected float CalculateMaxAcceleration() {
float maxReferenceAcceleration =
(float)(_staticConfig.accelerationConfig.maxReferenceAcceleration * Constants.kGravity);
float referenceSpeed = _staticConfig.accelerationConfig.referenceSpeed;
return Mathf.Pow(GetComponent<Rigidbody>().linearVelocity.magnitude / referenceSpeed, 2) *
maxReferenceAcceleration;
}
protected Vector3 CalculateGravityProjectionOnPitchAndYaw() {
Vector3 gravity = Physics.gravity;
Vector3 pitchAxis = transform.right;
Vector3 yawAxis = transform.up;
// Project the gravity onto the pitch and yaw axes
float gravityProjectionPitchCoefficient = Vector3.Dot(gravity, pitchAxis);
float gravityProjectionYawCoefficient = Vector3.Dot(gravity, yawAxis);
// Return the sum of the projections
return gravityProjectionPitchCoefficient * pitchAxis +
gravityProjectionYawCoefficient * yawAxis;
}
private float CalculateDrag() {
float dragCoefficient = _staticConfig.liftDragConfig.dragCoefficient;
float crossSectionalArea = _staticConfig.bodyConfig.crossSectionalArea;
float mass = _staticConfig.bodyConfig.mass;
float dynamicPressure = (float)GetDynamicPressure();
float dragForce = dragCoefficient * dynamicPressure * crossSectionalArea;
return dragForce / mass;
}
private float CalculateLiftInducedDrag(Vector3 accelerationInput) {
float liftAcceleration =
(accelerationInput - Vector3.Dot(accelerationInput, transform.up) * transform.up).magnitude;
float liftDragRatio = _staticConfig.liftDragConfig.liftDragRatio;
return Mathf.Abs(liftAcceleration / liftDragRatio);
}
// ===========================================================
// STRATEGIES
// ===========================================================
/// <summary>
/// Strategy for moving the Threat in a straight path towards its target.
/// </summary>
public class DirectPathStrategy : NavigationStrategy {
DefendPoint target = new DefendPoint();
private float _navigationGain = 3f; // Typically 3-5
private SensorOutput _sensorOutput;
private Vector3 _accelerationCommand;
private double _elapsedTime = 0;
public override void Execute(Threat threat, List<Threat> swarmMates, FlightPhase flightPhase,
List<Interceptor> interceptors, double deltaTime) {
RollStabilizedMissileThreat missileThreat = threat as RollStabilizedMissileThreat;
if (missileThreat == null) {
Debug.LogError("DirectPathStrategy can only be used with RollStabilizedMissileThreat");
return;
}
_elapsedTime += deltaTime;
Vector3 accelerationInput = Vector3.zero;
if (target != null) {
// Correct the state of the threat model at the sensor frequency
float sensorUpdatePeriod =
1f / missileThreat._agentConfig.dynamic_config.sensor_config.frequency;
if (_elapsedTime >= sensorUpdatePeriod) {
_sensorOutput = new SensorOutput();
missileThreat.GetComponent<Sensor>().Sense(target);
Debug.Log(_sensorOutput.velocity.range);
_elapsedTime = 0;
}
// Check whether the threat should be considered a miss
SensorOutput sensorOutput = missileThreat.GetComponent<Sensor>().Sense(target);
if (sensorOutput.velocity.range > 1000f) {
missileThreat.MarkAsMiss();
}
// Calculate the acceleration input
accelerationInput = CalculateAccelerationCommand(missileThreat, _sensorOutput);
} else {
Debug.LogError("DirectPathStrategy requires a target to be set");
}
// Calculate and set the total acceleration
Vector3 acceleration =
missileThreat.CalculateAcceleration(accelerationInput, compensateForGravity: true);
missileThreat.GetComponent<Rigidbody>().AddForce(acceleration, ForceMode.Acceleration);
}
private Vector3 CalculateAccelerationCommand(Threat threat, SensorOutput sensorOutput) {
RollStabilizedMissileThreat missileThreat = threat as RollStabilizedMissileThreat;
// Implement Proportional Navigation guidance law
Vector3 accelerationCommand;
// Extract relevant information from sensor output
float los_rate_az = sensorOutput.velocity.azimuth;
float los_rate_el = sensorOutput.velocity.elevation;
float closing_velocity =
-sensorOutput.velocity
.range; // Negative because closing velocity is opposite to range rate
// Navigation gain (adjust as needed)
float N = _navigationGain;
// Calculate acceleration commands in azimuth and elevation planes
float acc_az = N * closing_velocity * los_rate_az;
float acc_el = N * closing_velocity * los_rate_el;
// Convert acceleration commands to craft body frame
accelerationCommand =
missileThreat.transform.right * acc_az + missileThreat.transform.up * acc_el;
// Clamp the acceleration command to the maximum acceleration
float maxAcceleration = missileThreat.CalculateMaxAcceleration();
accelerationCommand = Vector3.ClampMagnitude(accelerationCommand, maxAcceleration);
// Update the stored acceleration command for debugging
_accelerationCommand = accelerationCommand;
return accelerationCommand;
}
}
/// <summary>
/// Strategy for moving the Threat in a spiral towards a predefined target.
/// </summary>
public class SpiralStrategy : NavigationStrategy {
private float spiralRadius;
private float periodDistance;
public SpiralStrategy(float spiralRadius, float periodDistance) {
this.spiralRadius = spiralRadius;
this.periodDistance = periodDistance;
}
public override void Execute(Threat threat, List<Threat> swarmMates, FlightPhase flightPhase,
List<Interceptor> interceptors, double deltaTime) {
throw new System.NotImplementedException();
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0d798867791c1444b985d8807b144572
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3,6 +3,29 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public abstract class Threat : Agent { public abstract class Threat : Agent {
/// <summary>
/// Strategy for moving the Threat towards a predefined target.
/// </summary>
public abstract class NavigationStrategy {
/// <summary>
/// Execute one timestep of the strategy for the given threat and flight phase. Should only
/// apply normal forces to the threat. Can also change the threat's flight phase. Should NOT
/// manage thrust.
/// </summary>
/// <param name="threat">Parent Threat object</param>
/// <param name="swarmMates">List of other threats in the swarm</param>
/// <param name="flightPhase">Current flight phase</param>
/// <param name="interceptors">List of active interceptors</param>
/// <param name="deltaTime">Timestep</param>
public abstract void Execute(Threat threat, List<Threat> swarmMates, FlightPhase flightPhase,
List<Interceptor> interceptors, double deltaTime);
}
/// <summary>
/// Navigation strategy that this threat will use to move towards its target.
/// </summary>
public NavigationStrategy strategy;
public override bool IsAssignable() { public override bool IsAssignable() {
return false; return false;
} }
@ -13,5 +36,18 @@ public abstract class Threat : Agent {
protected override void FixedUpdate() { protected override void FixedUpdate() {
base.FixedUpdate(); base.FixedUpdate();
// NOTE: no swarm-mates for now
strategy.Execute(this, new List<Threat>(), GetFlightPhase(),
SimManager.Instance.GetActiveInterceptors(), Time.fixedDeltaTime);
}
/// <summary>
/// OVERRIDE: THIS SHOULD NEVER BE CALLED; threats always start in midcourse or (at the very
/// earliest) boost phase.
/// </summary>
/// <param name="deltaTime"></param>
/// <exception cref="System.NotImplementedException"></exception>
protected override void UpdateReady(double deltaTime) {
throw new System.NotImplementedException();
} }
} }

View File

@ -5,7 +5,7 @@
"num_agents": 1, "num_agents": 1,
"agent_config": { "agent_config": {
"interceptor_type": "HYDRA_70", "interceptor_type": "HYDRA_70",
"threat_type": "DRONE", "threat_type": "ROLL_STABILIZED_MISSILE",
"initial_state": { "initial_state": {
"position": { "position": {
"x": 0, "x": 0,
@ -98,8 +98,7 @@
{ {
"num_agents": 7, "num_agents": 7,
"agent_config": { "agent_config": {
"interceptor_type": "HYDRA_70", "threat_type": "ROLL_STABILIZED_MISSILE",
"threat_type": "MISSILE",
"initial_state": { "initial_state": {
"position": { "position": {
"x": 0, "x": 0,
@ -108,7 +107,7 @@
}, },
"rotation": { "rotation": {
"x": 90, "x": 90,
"y": 0, "y": 50,
"z": 0 "z": 0
}, },
"velocity": { "velocity": {
@ -137,9 +136,6 @@
"type": "IDEAL", "type": "IDEAL",
"frequency": 0 "frequency": 0
} }
},
"static_config": {
}, },
"submunitions_config": { "submunitions_config": {
"num_submunitions": 0 "num_submunitions": 0

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 22c1e00f13b5ec6468892b8c6df37933
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,25 @@
{
"accelerationConfig": {
"maxReferenceAcceleration": 300,
"referenceSpeed": 1000
},
"boostConfig": {
"boostTime": 0.3,
"boostAcceleration": 350
},
"liftDragConfig": {
"liftCoefficient": 0.2,
"dragCoefficient": 0.7,
"liftDragRatio": 5
},
"bodyConfig": {
"mass": 0.37,
"crossSectionalArea": 0.0003,
"finArea": 0.0006,
"bodyArea": 0.01
},
"hitConfig": {
"hitRadius": 1,
"killProbability": 0.9
}
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 72573475cbd372d4dbb25291cc6545b0
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: