micromissiles-unity/Assets/Scripts/Interceptors/Hydra70.cs

54 lines
1.9 KiB
C#
Raw Normal View History

2024-09-12 15:44:55 -07:00
using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;
2024-09-24 19:59:25 -07:00
public class Hydra70 : Interceptor {
2024-09-13 22:45:25 -07:00
private bool _submunitionsLaunched = false;
protected override void FixedUpdate() {
base.FixedUpdate();
2024-09-13 22:45:25 -07:00
// Check if it's time to launch submunitions
if (!_submunitionsLaunched &&
(GetFlightPhase() == FlightPhase.MIDCOURSE || GetFlightPhase() == FlightPhase.BOOST) &&
SimManager.Instance.GetElapsedSimulationTime() >=
_agentConfig.submunitions_config.launch_config.launch_time) {
SpawnSubmunitions();
_submunitionsLaunched = true;
2024-09-12 15:44:55 -07:00
}
2024-09-13 22:45:25 -07:00
}
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 override void DrawDebugVectors() {
base.DrawDebugVectors();
if (_acceleration != null) {
Debug.DrawRay(transform.position, _acceleration * 1f, Color.green);
2024-09-12 15:44:55 -07:00
}
2024-09-13 22:45:25 -07:00
}
public void SpawnSubmunitions() {
2024-09-24 19:59:25 -07:00
List<Interceptor> submunitions = new List<Interceptor>();
switch (_agentConfig.submunitions_config.agent_config.interceptor_type) {
case InterceptorType.MICROMISSILE:
2024-09-13 22:45:25 -07:00
for (int i = 0; i < _agentConfig.submunitions_config.num_submunitions; i++) {
AgentConfig convertedConfig =
AgentConfig.FromSubmunitionAgentConfig(_agentConfig.submunitions_config.agent_config);
convertedConfig.initial_state.position = transform.position;
2024-09-25 17:51:44 -07:00
convertedConfig.initial_state.velocity = GetComponent<Rigidbody>().linearVelocity;
2024-09-24 19:59:25 -07:00
Interceptor submunition = SimManager.Instance.CreateInterceptor(convertedConfig);
2024-09-13 22:45:25 -07:00
submunitions.Add(submunition);
2024-09-12 15:44:55 -07:00
}
2024-09-13 22:45:25 -07:00
break;
2024-09-12 15:44:55 -07:00
}
IADS.Instance.RequestThreatAssignment(submunitions);
2024-09-13 22:45:25 -07:00
}
2024-09-12 15:44:55 -07:00
}