Search Unity

How to get value of distance between agent obstacles with using RayPerceptionSensor3D?

Discussion in 'ML-Agents' started by als795, Jan 22, 2021.

  1. als795

    als795

    Joined:
    Nov 16, 2020
    Posts:
    6
    Hello.

    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.

    Thanks :)
     
  2. Sab_Rango

    Sab_Rango

    Joined:
    Aug 30, 2019
    Posts:
    121
    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.
     
    als795 likes this.
  3. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    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.
     
    als795 likes this.
  4. als795

    als795

    Joined:
    Nov 16, 2020
    Posts:
    6