diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs b/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs deleted file mode 100644 index 45744fa1fa..0000000000 --- a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -[Obsolete] -public abstract class RayPerception : MonoBehaviour -{ - protected float[] m_PerceptionBuffer; - - abstract public IList Perceive(float rayDistance, - float[] rayAngles, string[] detectableObjects, - float startOffset=0.0f, float endOffset=0.0f); - - -} diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs.meta b/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs.meta deleted file mode 100644 index e0ea215582..0000000000 --- a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a14e2e238ae844231bc2c88e17bae5a5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception2D.cs b/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception2D.cs deleted file mode 100644 index 2d76754b19..0000000000 --- a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception2D.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using MLAgents.Sensor; - -namespace MLAgents -{ - /// - /// Ray 2D perception component. Attach this to agents to enable "local perception" - /// via the use of ray casts directed outward from the agent. - /// - [Obsolete("The RayPerception MonoBehaviour is deprecated. Use the RayPerceptionSensorComponent instead")] - public class RayPerception2D : RayPerception - { - RaycastHit2D m_Hit; - - /// - /// Creates perception vector to be used as part of an observation of an agent. - /// Each ray in the rayAngles array adds a sublist of data to the observation. - /// The sublist contains the observation data for a single ray. The list is composed of the following: - /// 1. A one-hot encoding for detectable objects. For example, if detectableObjects.Length = n, the - /// first n elements of the sublist will be a one-hot encoding of the detectableObject that was hit, or - /// all zeroes otherwise. - /// 2. The 'length' element of the sublist will be 1 if the ray missed everything, or 0 if it hit - /// something (detectable or not). - /// 3. The 'length+1' element of the sublist will contain the normalised distance to the object hit. - /// NOTE: Only objects with tags in the detectableObjects array will have a distance set. - /// - /// The partial vector observation corresponding to the set of rays - /// Radius of rays - /// Angles of rays (starting from (1,0) on unit circle). - /// List of tags which correspond to object types agent can see - /// Unused - /// Unused - public override IList Perceive(float rayDistance, - float[] rayAngles, string[] detectableObjects, - float startOffset=0.0f, float endOffset=0.0f) - { - var perceptionSize = (detectableObjects.Length + 2) * rayAngles.Length; - if (m_PerceptionBuffer == null || m_PerceptionBuffer.Length != perceptionSize) - { - m_PerceptionBuffer = new float[perceptionSize]; - } - - const float castRadius = 0.5f; - const bool legacyHitFractionBehavior = true; - RayPerceptionSensor.PerceiveStatic( - rayDistance, rayAngles, detectableObjects, startOffset, endOffset, castRadius, - transform, RayPerceptionSensor.CastType.Cast3D, m_PerceptionBuffer, legacyHitFractionBehavior - ); - - return m_PerceptionBuffer; - } - - } -} diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception2D.cs.meta b/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception2D.cs.meta deleted file mode 100644 index cc2d00f87d..0000000000 --- a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception2D.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 59a9c4378bb2a40c49eb7a248c52fbf5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception3D.cs b/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception3D.cs deleted file mode 100644 index 8054effe2d..0000000000 --- a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception3D.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using MLAgents.Sensor; - -namespace MLAgents -{ - /// - /// Ray perception component. Attach this to agents to enable "local perception" - /// via the use of ray casts directed outward from the agent. - /// - [Obsolete("The RayPerception MonoBehaviour is deprecated. Use the RayPerceptionSensorComponent instead")] - public class RayPerception3D : RayPerception - { - /// - /// Creates perception vector to be used as part of an observation of an agent. - /// Each ray in the rayAngles array adds a sublist of data to the observation. - /// The sublist contains the observation data for a single ray. The list is composed of the following: - /// 1. A one-hot encoding for detectable objects. For example, if detectableObjects.Length = n, the - /// first n elements of the sublist will be a one-hot encoding of the detectableObject that was hit, or - /// all zeroes otherwise. - /// 2. The 'length' element of the sublist will be 1 if the ray missed everything, or 0 if it hit - /// something (detectable or not). - /// 3. The 'length+1' element of the sublist will contain the normalised distance to the object hit. - /// NOTE: Only objects with tags in the detectableObjects array will have a distance set. - /// - /// The partial vector observation corresponding to the set of rays - /// Radius of rays - /// Angles of rays (starting from (1,0) on unit circle). - /// List of tags which correspond to object types agent can see - /// Starting height offset of ray from center of agent. - /// Ending height offset of ray from center of agent. - public override IList Perceive(float rayDistance, - float[] rayAngles, string[] detectableObjects, - float startOffset=0.0f, float endOffset=0.0f) - { - var perceptionSize = (detectableObjects.Length + 2) * rayAngles.Length; - if (m_PerceptionBuffer == null || m_PerceptionBuffer.Length != perceptionSize) - { - m_PerceptionBuffer = new float[perceptionSize]; - } - - const float castRadius = 0.5f; - const bool legacyHitFractionBehavior = true; - RayPerceptionSensor.PerceiveStatic( - rayDistance, rayAngles, detectableObjects, startOffset, endOffset, castRadius, - transform, RayPerceptionSensor.CastType.Cast3D, m_PerceptionBuffer, legacyHitFractionBehavior - ); - - return m_PerceptionBuffer; - } - - - } -} diff --git a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception3D.cs.meta b/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception3D.cs.meta deleted file mode 100644 index 0344f3ebb0..0000000000 --- a/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception3D.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: bb172294dbbcc408286b156a2c4b553c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.ml-agents/Runtime/Sensor/RayPerceptionSensor.cs b/com.unity.ml-agents/Runtime/Sensor/RayPerceptionSensor.cs index ec51458eb3..2a29cff98c 100644 --- a/com.unity.ml-agents/Runtime/Sensor/RayPerceptionSensor.cs +++ b/com.unity.ml-agents/Runtime/Sensor/RayPerceptionSensor.cs @@ -100,7 +100,7 @@ public int Write(WriteAdapter adapter) { PerceiveStatic( m_RayDistance, m_Angles, m_DetectableObjects, m_StartOffset, m_EndOffset, - m_CastRadius, m_Transform, m_CastType, m_Observations, false, m_LayerMask, + m_CastRadius, m_Transform, m_CastType, m_Observations, m_LayerMask, m_DebugDisplayInfo ); adapter.AddRange(m_Observations); @@ -144,10 +144,6 @@ public virtual SensorCompressionType GetCompressionType() /// 3. The 'length+1' element of the sublist will contain the normalised distance to the object hit, or 1 if /// nothing was hit. /// - /// The legacyHitFractionBehavior changes the behavior to be backwards compatible but has some - /// counter-intuitive behavior: - /// * if the cast hits a object that's not in the detectableObjects list, all results are 0 - /// * if the cast doesn't hit, the hit fraction field is 0 /// /// /// List of angles (in degrees) used to define the rays. 90 degrees is considered @@ -160,14 +156,12 @@ public virtual SensorCompressionType GetCompressionType() /// Transform of the GameObject /// Whether to perform the casts in 2D or 3D. /// Output array of floats. Must be (num rays) * (num tags + 2) in size. - /// Whether to use the legacy behavior for hit fractions. /// Optional debug information output, only used by RayPerceptionSensor. /// public static void PerceiveStatic(float rayLength, IReadOnlyList rayAngles, IReadOnlyList detectableObjects, float startOffset, float endOffset, float castRadius, Transform transform, CastType castType, float[] perceptionBuffer, - bool legacyHitFractionBehavior = false, int layerMask = Physics.DefaultRaycastLayers, DebugDisplayInfo debugInfo = null) { @@ -212,10 +206,6 @@ public static void PerceiveStatic(float rayLength, // sublist[numObjects-1] <- did hit detectableObjects[numObjects-1] // sublist[numObjects ] <- 1 if missed else 0 // sublist[numObjects+1] <- hit fraction (or 1 if no hit) - // The legacyHitFractionBehavior changes the behavior to be backwards compatible but has some - // counter-intuitive behavior: - // * if the cast hits a object that's not in the detectableObjects list, all results are 0 - // * if the cast doesn't hit, the hit fraction field is 0 bool castHit; float hitFraction; @@ -285,7 +275,7 @@ public static void PerceiveStatic(float rayLength, } } - if (!hitTaggedObject && !legacyHitFractionBehavior) + if (!hitTaggedObject) { // Something was hit but not on the list. Still set the hit fraction. perceptionBuffer[bufferOffset + detectableObjects.Count + 1] = hitFraction; @@ -294,11 +284,8 @@ public static void PerceiveStatic(float rayLength, else { perceptionBuffer[bufferOffset + detectableObjects.Count] = 1f; - if (!legacyHitFractionBehavior) - { - // Nothing was hit, so there's full clearance in front of the agent. - perceptionBuffer[bufferOffset + detectableObjects.Count + 1] = 1.0f; - } + // Nothing was hit, so there's full clearance in front of the agent. + perceptionBuffer[bufferOffset + detectableObjects.Count + 1] = 1.0f; } bufferOffset += detectableObjects.Count + 2;