Fixed to target assignment, 3 salvo hydra70 config

more-targets
Daniel Lovell 2024-09-12 23:58:47 -07:00
parent 488ddaa836
commit 25e6568023
7 changed files with 144 additions and 25 deletions

View File

@ -106,7 +106,7 @@ Material:
- _Parallax: 0.02
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.556
- _Smoothness: 0.33
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1

View File

@ -65,6 +65,10 @@ public abstract class Agent : MonoBehaviour
_target = target;
}
public Agent GetAssignedTarget() {
return _target;
}
public bool HasAssignedTarget() {
return _target != null;
}
@ -90,7 +94,7 @@ public abstract class Agent : MonoBehaviour
}
public void TerminateAgent() {
_flightPhase = FlightPhase.TERMINATED;
_flightPhase = FlightPhase.TERMINATED;
transform.position = new Vector3(0, 0, 0);
gameObject.SetActive(false);
}
@ -103,6 +107,10 @@ public abstract class Agent : MonoBehaviour
public void MarkAsMiss() {
_isMiss = true;
if(_target != null) {
SimManager.Instance.RegisterTargetMiss(_target as Target);
_target = null;
}
TerminateAgent();
}

View File

@ -34,9 +34,27 @@ public class ThreatAssignment : IAssignment
if (missiles[missileIndex].HasAssignedTarget()) continue;
if (threatInfos.Count == 0) break;
ThreatInfo highestThreat = threatInfos[0];
assignments.Add(new IAssignment.AssignmentItem(missileIndex, highestThreat.TargetIndex));
threatInfos.RemoveAt(0);
// Find the optimal target for this missile based on distance and threat
ThreatInfo optimalTarget = null;
float optimalScore = float.MinValue;
foreach (ThreatInfo threat in threatInfos)
{
float distance = Vector3.Distance(missiles[missileIndex].transform.position, targets[threat.TargetIndex].transform.position);
float score = threat.ThreatLevel / distance; // Balance threat level with proximity
if (score > optimalScore)
{
optimalScore = score;
optimalTarget = threat;
}
}
if (optimalTarget != null)
{
assignments.Add(new IAssignment.AssignmentItem(missileIndex, optimalTarget.TargetIndex));
threatInfos.Remove(optimalTarget);
}
}
return assignments;
}

View File

@ -4,7 +4,7 @@ using UnityEngine;
public class Micromissile : Missile
{
[SerializeField] private float _navigationGain = 3f; // Typically 3-5
[SerializeField] private float _navigationGain = 5f; // Typically 3-5
private SensorOutput _sensorOutput;
private Vector3 _accelerationCommand;
@ -32,7 +32,6 @@ public class Micromissile : Missile
SensorOutput sensorOutput = GetComponent<Sensor>().Sense(_target);
if(sensorOutput.velocity.range > 1000f) {
this.MarkAsMiss();
_target.MarkAsMiss();
}
// Calculate the acceleration input

View File

@ -29,7 +29,7 @@ public class Missile : Agent
protected override void UpdateReady(double deltaTime) {
Vector3 accelerationInput = Vector3.zero;
Vector3 acceleration = CalculateAcceleration(accelerationInput);
GetComponent<Rigidbody>().AddForce(acceleration, ForceMode.Acceleration);
//GetComponent<Rigidbody>().AddForce(acceleration, ForceMode.Acceleration);
}
protected override void Update() {

View File

@ -15,8 +15,8 @@ public class SimManager : MonoBehaviour
private List<Missile> _missiles = new List<Missile>();
private HashSet<Target> _unassignedTargets = new HashSet<Target>();
private HashSet<Target> _targets = new HashSet<Target>();
private List<Target> _unassignedTargets = new List<Target>();
private List<Target> _targets = new List<Target>();
private float _elapsedSimulationTime = 0f;
private float endTime = 100f; // Set an appropriate end time
private bool simulationRunning = false;
@ -83,6 +83,10 @@ public class SimManager : MonoBehaviour
AssignMissilesToTargets(_missiles);
}
public void RegisterTargetMiss(Target target) {
_unassignedTargets.Add(target);
}
public void AssignMissilesToTargets(List<Missile> missilesToAssign)
{
@ -100,12 +104,14 @@ public class SimManager : MonoBehaviour
if (assignment.MissileIndex < missilesToAssign.Count)
{
Missile missile = missilesToAssign[assignment.MissileIndex];
Target target = _targets.ElementAt(assignment.TargetIndex);
Target target = _unassignedTargets[assignment.TargetIndex];
missile.AssignTarget(target);
Debug.Log($"Missile {missile.name} assigned to target {target.name}");
_unassignedTargets.Remove(target);
}
}
// TODO this whole function should be optimized
_unassignedTargets.RemoveAll(target => missilesToAssign.Any(missile => missile.GetAssignedTarget() == target));
}
public Missile CreateMissile(AgentConfig config)

View File

@ -12,25 +12,25 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 79f1fe138866d6a40b209a4edcf2ee06, type: 3}
m_Name: SimulationConfigHydra70
m_EditorClassIdentifier:
timeScale: 0.2
timeScale: 1
missile_swarm_configs:
- num_agents: 20
- num_agents: 10
agent_config:
missile_type: 0
target_type: 0
initial_state:
position: {x: 0, y: 10, z: 0}
position: {x: 0, y: 20, z: 0}
rotation: {x: -45, y: 0, z: 0}
velocity: {x: 0, y: 10, z: 10}
standard_deviation:
position: {x: 10, y: 10, z: 10}
velocity: {x: 5, y: 0, z: 5}
position: {x: 10, y: 0, z: 10}
velocity: {x: 5, y: 0, z: 1}
dynamic_config:
launch_config:
launch_time: 0
sensor_config:
type: 0
frequency: 1
frequency: 1000
plotting_config:
color: {r: 0, g: 0, b: 0, a: 0}
linestyle: 0
@ -38,13 +38,101 @@ MonoBehaviour:
submunitions_config:
num_submunitions: 7
launch_config:
launch_time: 1.5
launch_time: 2
agent_config:
missile_type: 1
initial_state:
position: {x: -38.074936, y: 286.19226, z: 293.8709}
position: {x: -276.48438, y: 585.0613, z: 640.66565}
rotation: {x: 0, y: 0, z: 0}
velocity: {x: -20.437624, y: 181.02332, z: 193.21309}
velocity: {x: -115.62746, y: 195.53085, z: 266.85275}
standard_deviation:
position: {x: 5, y: 5, z: 5}
velocity: {x: 0, y: 0, z: 0}
dynamic_config:
launch_config:
launch_time: 0
sensor_config:
type: 0
frequency: 1
plotting_config:
color: {r: 0, g: 0, b: 0, a: 0}
linestyle: 0
marker: 0
- num_agents: 10
agent_config:
missile_type: 0
target_type: 0
initial_state:
position: {x: 200, y: 20, z: 0}
rotation: {x: -60, y: 0, z: 0}
velocity: {x: 0, y: 10, z: 12}
standard_deviation:
position: {x: 10, y: 0, z: 10}
velocity: {x: 5, y: 0, z: 1}
dynamic_config:
launch_config:
launch_time: 10
sensor_config:
type: 0
frequency: 1000
plotting_config:
color: {r: 0, g: 0, b: 0, a: 0}
linestyle: 0
marker: 0
submunitions_config:
num_submunitions: 7
launch_config:
launch_time: 12
agent_config:
missile_type: 1
initial_state:
position: {x: -142.09969, y: 732.03265, z: 973.45154}
rotation: {x: 0, y: 0, z: 0}
velocity: {x: -127.14329, y: 235.90274, z: 367.02448}
standard_deviation:
position: {x: 5, y: 5, z: 5}
velocity: {x: 0, y: 0, z: 0}
dynamic_config:
launch_config:
launch_time: 0
sensor_config:
type: 0
frequency: 1
plotting_config:
color: {r: 0, g: 0, b: 0, a: 0}
linestyle: 0
marker: 0
- num_agents: 10
agent_config:
missile_type: 0
target_type: 0
initial_state:
position: {x: -100, y: 20, z: 0}
rotation: {x: -45, y: 0, z: 0}
velocity: {x: 0, y: 10, z: 10}
standard_deviation:
position: {x: 10, y: 0, z: 10}
velocity: {x: 5, y: 0, z: 3}
dynamic_config:
launch_config:
launch_time: 20
sensor_config:
type: 0
frequency: 1000
plotting_config:
color: {r: 0, g: 0, b: 0, a: 0}
linestyle: 0
marker: 0
submunitions_config:
num_submunitions: 7
launch_config:
launch_time: 23
agent_config:
missile_type: 1
initial_state:
position: {x: -117.94113, y: 473.32446, z: 1092.305}
rotation: {x: 0, y: 0, z: 0}
velocity: {x: -5.810343, y: 133.54488, z: 394.63327}
standard_deviation:
position: {x: 5, y: 5, z: 5}
velocity: {x: 0, y: 0, z: 0}
@ -64,12 +152,12 @@ MonoBehaviour:
missile_type: 0
target_type: 0
initial_state:
position: {x: 0, y: 400, z: 3000}
position: {x: 0, y: 600, z: 6000}
rotation: {x: 90, y: 0, z: 0}
velocity: {x: 0, y: 0, z: -150}
velocity: {x: 0, y: 0, z: -50}
standard_deviation:
position: {x: 500, y: 200, z: 100}
velocity: {x: 0, y: 0, z: 50}
position: {x: 1000, y: 200, z: 100}
velocity: {x: 0, y: 0, z: 25}
dynamic_config:
launch_config:
launch_time: 0