How can I use RayPerceptionComponent3D effectively?

Hi, I downloaded Karting Microgame and am trying to learn how to use ML- Agents package.
I updated ml- agents package to 1.0.2 and realized that it contains RayPerceptionComponent3D component for ray observations. I wonder how to reedit this CollectObservation function using this component?

public override void CollectObservations()
        {
            AddVectorObs(kart.LocalSpeed());

            // Add an observation for direction of the agent to the next checkpoint.
            var next          = (checkpointIndex + 1) % Colliders.Length;
            var nextCollider  = Colliders[next];
            var direction     = (nextCollider.transform.position - kart.transform.position).normalized;
            AddVectorObs(Vector3.Dot(kart.Rigidbody.velocity.normalized, direction));

            if (ShowRaycasts)
            {
                Debug.DrawLine(AgentSensorTransform.position, nextCollider.transform.position, Color.magenta);
            }

            for (int i = 0; i < Sensors.Length; i++)
            {
                var current = Sensors[i];
                var xform   = current.Transform;
                var hit     = Physics.Raycast(AgentSensorTransform.position, xform.forward, out var hitInfo,
                    RaycastDistance, Mask, QueryTriggerInteraction.Ignore);

                if (ShowRaycasts)
                {
                    Debug.DrawRay(AgentSensorTransform.position, xform.forward * RaycastDistance, Color.green);
                    Debug.DrawRay(AgentSensorTransform.position, xform.forward * RaycastDistance * current.HitThreshold,
                        Color.red);
                }

                var hitDistance = (hit ? hitInfo.distance : RaycastDistance) / RaycastDistance;
                AddVectorObs(hitDistance);

                if (hitDistance < current.HitThreshold) {
                    AddReward(HitPenalty);
                    Done();
                    AgentReset();
                }
            }
        }

I think there is no need to raycasts anymore when I use rayperceptioncomponent3D but
I don’t know how to make this control if I need :
if (hitDistance < current.HitThreshold)

I have not found any code examples of this component, I would be glad if you could help.

No need to code if you use the RayPerceptionSensor3D Component. If you attach one to your agent all you need is configure the parameters in the editor; no need to add any code in the script since it will treat the raycasting as an observation by itself.

The observations collected by a raycast sensor is added internally to the agent’s observations which has the raycast script attached. There is no coding necessary and nothing to account for in the behavior parameters script.

Okay, I understood that we don’t need to collect observations of raycasts anymore.
But how to process these observations?
For example, we have to reset agent if it follows wrong raycast and crash, or we want to add reward if it follows correct raycast.
But now we can not do that.
I would be glad if you can explain with an example.

You are now in reward engineering. You can code that if the agent hits specific colliders then it receives -1 as a reward and then reset. Otherwise, you could give +1 if it reaches its final destination.

Or give it small rewards +0.01 or +0.001 when it reaches checkpoints and saves the +1 to the end.

It really depends on what you want to achieve.

We are doing what you say already. But we also want to use raycasts to process,
you can see this method used in unity example project’s code that I shared first :

for (int i = 0; i < Sensors.Length; i++)
            {
                var current = Sensors[i];
                var xform   = current.Transform;
                var hit     = Physics.Raycast(AgentSensorTransform.position, xform.forward, out var hitInfo,
                    RaycastDistance, Mask, QueryTriggerInteraction.Ignore);
                if (ShowRaycasts)
                {
                    Debug.DrawRay(AgentSensorTransform.position, xform.forward * RaycastDistance, Color.green);
                    Debug.DrawRay(AgentSensorTransform.position, xform.forward * RaycastDistance * current.HitThreshold,
                        Color.red);
                }
                var hitDistance = (hit ? hitInfo.distance : RaycastDistance) / RaycastDistance;
                AddVectorObs(hitDistance);
                if (hitDistance < current.HitThreshold) {
                    AddReward(HitPenalty);
                    Done();
                    AgentReset();
                }
            }

On the conclusion, we want to learn how to use this component and its parameters, events, features etc. for using in our future projects. There is no enough detailed knowledge about this. We would be glad if you can share detailed document with us.

Thank you.