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.