I’ve been using ML-Agents for a research of reinforcement learning and I’d like to get a value of distance between the agent and obstacles with using Ray Perception Sensor.
According to some references or blogs, to use Ray Perception Sensor, we have to add RayPerceptionSensor3D component and set some parameters of this component.
I did these process, but I still have no idea how to get the distance. If anyone know some methods or ideas, please let me know.
Hey!
Indeed, RayPerceptionSensor3D component automatically adds observations into the Network observations list, so no need to write code for it. link to expl. forum How to create these perception rays? - Unity Forum
But, if you try to see source code and get the distance value, the source code are located in this directory:
Packages\ml-agents\Runtime\Sensors\RayPerceptionSensorComponent.c#, ect.
As @Sab_Rango said, if you just want your agent to use the raycasts as observations to learn from, just add a RayPerceptionSensor3D and start training.
If you really want to handle the observations manually, you can use RayPerceptionSensor.Perceive(), which is a static method. The RayPerceptionOutput struct will contain the normalized distances (between 0 and 1) of the ray hits.