From 73dc5a5750ec5780c8d352e6b36e31f91f2f91e7 Mon Sep 17 00:00:00 2001
From: Ariel Kwiatkowski <ariel.j.kwiatkowski@gmail.com>
Date: Mon, 16 May 2022 01:34:44 +0200
Subject: [PATCH] Reorder angles in RayPerceptionSensor

---
 .../Sensors/RayPerceptionSensorComponentBase.cs       | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs
index 7ae924e839..fa39c32ac7 100644
--- a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs
+++ b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs
@@ -209,15 +209,16 @@ public override ISensor[] CreateSensors()
         internal static float[] GetRayAngles(int raysPerDirection, float maxRayDegrees)
         {
             // Example:
-            // { 90, 90 - delta, 90 + delta, 90 - 2*delta, 90 + 2*delta }
+            // { 90 - 3*delta, 90 - 2*delta, ..., 90, 90 + delta, ..., 90 + 3*delta }
             var anglesOut = new float[2 * raysPerDirection + 1];
             var delta = maxRayDegrees / raysPerDirection;
-            anglesOut[0] = 90f;
-            for (var i = 0; i < raysPerDirection; i++)
+            
+            for (var i =  0; i < 2 * raysPerDirection + 1; i++)
             {
-                anglesOut[2 * i + 1] = 90 - (i + 1) * delta;
-                anglesOut[2 * i + 2] = 90 + (i + 1) * delta;
+                // 90 - (num_rays) * delta + i * delta
+                anglesOut[i] = 90 - (raysPerDirection - i) * delta;
             }
+            
             return anglesOut;
         }