Rendering and environment improvements

This commit is contained in:
Daniel Lovell
2024-09-12 11:39:23 -07:00
parent 742da94fe9
commit 2bc8af1ff3
104 changed files with 13846 additions and 220 deletions

View File

@@ -11,7 +11,6 @@ public abstract class Agent : MonoBehaviour
INITIALIZED,
READY,
BOOST,
MIDCOURSE,
TERMINAL,
TERMINATED

View File

@@ -4,7 +4,7 @@ using UnityEngine;
public class Micromissile : Missile
{
[SerializeField] private float navigationGain = 10f; // Typically 3-5
[SerializeField] private float navigationGain = 5f; // Typically 3-5
[SerializeField] private bool _showDebugVectors = true;
private Vector3 _previousLOS;
@@ -83,10 +83,10 @@ public class Micromissile : Missile
if (_target != null)
{
// Line of sight
Debug.DrawLine(transform.position, _target.transform.position, Color.white);
Debug.DrawLine(transform.position, _target.transform.position, new Color(1, 1, 1, 0.15f));
// Velocity vector
Debug.DrawRay(transform.position, GetVelocity()*0.01f, Color.blue);
Debug.DrawRay(transform.position, GetVelocity()*0.01f, new Color(0, 0, 1, 0.15f));
// Acceleration input
Debug.DrawRay(transform.position, _accelerationCommand*1f, Color.green);

View File

@@ -73,6 +73,10 @@ public class Missile : Agent
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.name == "Floor") {
this.MarkAsMiss();
}
// Check if the collision is with another Agent
Agent otherAgent = other.gameObject.GetComponentInParent<Agent>();
if (otherAgent != null && otherAgent.GetComponent<Target>() != null)
@@ -83,7 +87,7 @@ public class Missile : Agent
if (Random.value <= killProbability)
{
// Set green for hit
markerObject.GetComponent<Renderer>().material.color = new Color(0, 1, 0, 0.5f);
markerObject.GetComponent<Renderer>().material.color = new Color(0, 1, 0, 0.15f);
// Mark both this agent and the other agent as hit
this.MarkAsHit();
otherAgent.MarkAsHit();
@@ -91,9 +95,9 @@ public class Missile : Agent
}
else {
// Set red for miss
markerObject.GetComponent<Renderer>().material.color = new Color(1, 0, 0, 0.5f);
markerObject.GetComponent<Renderer>().material.color = new Color(1, 0, 0, 0.15f);
this.MarkAsMiss();
otherAgent.MarkAsMiss();
//otherAgent.MarkAsMiss();
}
}

View File

@@ -41,77 +41,7 @@ public class IdealSensor : Sensor
return positionSensorOutput;
}
// protected override VelocityOutput SenseVelocity(Agent target)
// {
// VelocityOutput velocitySensorOutput = new VelocityOutput();
// // Calculate the relative position of the target with respect to the agent
// Vector3 position = _agent.transform.position;
// Vector3 targetPosition = target.transform.position;
// Vector3 targetRelativePosition = targetPosition - position;
// // Calculate the relative velocity of the target with respect to the agent
// Vector3 velocity = _agent.GetVelocity();
// Vector3 targetVelocity = target.GetVelocity();
// Vector3 targetRelativeVelocity = targetVelocity - velocity;
// // Project the relative velocity vector onto the relative position vector
// Vector3 velocityProjectionOnRelativePosition = Vector3.Project(targetRelativeVelocity, targetRelativePosition);
// // Determine the sign of the range rate
// float rangeRateSign = Vector3.Dot(velocityProjectionOnRelativePosition, targetRelativePosition) >= 0 ? 1 : -1;
// // Calculate the range rate
// velocitySensorOutput.range = rangeRateSign * velocityProjectionOnRelativePosition.magnitude;
// // Project the relative velocity vector onto the sphere passing through the target
// Vector3 velocityProjectionOnAzimuthElevationSphere = targetRelativeVelocity - velocityProjectionOnRelativePosition;
// // The target azimuth vector is orthogonal to the relative position vector and
// // points to the starboard of the target along the azimuth-elevation sphere
// Vector3 targetAzimuth = Vector3.Cross(targetRelativePosition, _agent.transform.forward).normalized;
// // The target elevation vector is orthogonal to the relative position vector
// // and points upwards from the target along the azimuth-elevation sphere
// Vector3 targetElevation = Vector3.Cross(targetAzimuth, targetRelativePosition).normalized;
// // If the relative position vector is parallel to the yaw or pitch axis, the
// // target azimuth vector or the target elevation vector will be undefined
// if (targetAzimuth.magnitude == 0)
// {
// // In this case, we can use the right vector as the azimuth
// targetAzimuth = _agent.transform.right;
// // And recalculate the elevation vector
// targetElevation = Vector3.Cross(targetAzimuth, targetRelativePosition).normalized;
// }
// else if (targetElevation.magnitude == 0)
// {
// targetElevation = Vector3.Cross(targetAzimuth, targetRelativePosition);
// }
// // Project the relative velocity vector on the azimuth-elevation sphere onto the target azimuth vector
// Vector3 velocityProjectionOnTargetAzimuth = Vector3.Project(velocityProjectionOnAzimuthElevationSphere, targetAzimuth);
// // Determine the sign of the azimuth velocity
// float azimuthVelocitySign = Vector3.Dot(velocityProjectionOnTargetAzimuth, targetAzimuth) >= 0 ? 1 : -1;
// // Calculate the time derivative of the azimuth to the target
// velocitySensorOutput.azimuth = azimuthVelocitySign * velocityProjectionOnTargetAzimuth.magnitude / targetRelativePosition.magnitude;
// // Project the velocity vector on the azimuth-elevation sphere onto the target elevation vector
// Vector3 velocityProjectionOnTargetElevation = velocityProjectionOnAzimuthElevationSphere - velocityProjectionOnTargetAzimuth;
// // Determine the sign of the elevation velocity
// float elevationVelocitySign = Vector3.Dot(velocityProjectionOnTargetElevation, targetElevation) >= 0 ? 1 : -1;
// // Calculate the time derivative of the elevation to the target
// velocitySensorOutput.elevation = elevationVelocitySign * velocityProjectionOnTargetElevation.magnitude / targetRelativePosition.magnitude;
// return velocitySensorOutput;
// }
protected override VelocityOutput SenseVelocity(Agent target)
{
VelocityOutput velocitySensorOutput = new VelocityOutput();

View File

@@ -9,10 +9,48 @@ public abstract class Sensor : MonoBehaviour
_agent = GetComponent<Agent>();
}
/// <summary>
/// Main sensing method to gather information about a target agent.
/// </summary>
/// <param name="target">The agent to sense.</param>
/// <returns>SensorOutput containing position and velocity data.</returns>
/// <remarks>
/// Implementers should:
/// 1. Call SensePosition to get position data.
/// 2. Call SenseVelocity to get velocity data.
/// 3. Combine results into a SensorOutput struct.
/// </remarks>
public abstract SensorOutput Sense(Agent target);
/// <summary>
/// Calculates the relative position of the target agent.
/// </summary>
/// <param name="target">The agent to sense.</param>
/// <returns>PositionOutput containing range, azimuth, and elevation.</returns>
/// <remarks>
/// Implementers should calculate:
/// - range: Distance to the target (in unity units).
/// - azimuth: Horizontal angle to the target (in degrees).
/// Positive is clockwise from the forward direction.
/// - elevation: Vertical angle to the target (in degrees).
/// Positive is above the horizontal plane.
/// </remarks>
protected abstract PositionOutput SensePosition(Agent target);
/// <summary>
/// Calculates the relative velocity of the target agent.
/// </summary>
/// <param name="target">The agent to sense.</param>
/// <returns>VelocityOutput containing range rate, azimuth rate, and elevation rate.</returns>
/// <remarks>
/// Implementers should calculate:
/// - range: Radial velocity (closing speed) in units/second.
/// Positive means the target is moving away.
/// - azimuth: Rate of change of azimuth in degrees/second.
/// Positive means the target is moving clockwise.
/// - elevation: Rate of change of elevation in degrees/second.
/// Positive means the target is moving upwards.
/// </remarks>
protected abstract VelocityOutput SenseVelocity(Agent target);
}