This commit is contained in:
2024-04-12 12:45:34 +02:00
parent 0b9d3b4950
commit aad2340c37
3 changed files with 58 additions and 12 deletions

View File

@@ -218,23 +218,27 @@ public class AgentController : Agent
float checkpintDistance = distanceToCheckpoint(currentCheckpoint);
print("forward " + transform.forward);
Vector3 checkpointDirection = currentCheckpoint.localPosition - transform.localPosition;
print("checkpoint direction " + checkpointDirection);
//print(angleToCheckpoint(currentCheckpoint));
// float reward = (1 - Mathf.InverseLerp(0, 20, checkpintDistance)) / 1000;
// AddReward(reward);
if (checkpintDistance < 0.1f)
{
Debug.Log(currentCheckpoint.name);
currentCheckpoint.GetComponent<Checkpoint>().isCollected = true;
stepsSinceCheckpoint = 0;
if (currentCheckpoint == checkpoints[checkpoints.Count - 1].transform)
{
AddReward(10f);
EndEpisode();
Debug.Log("END");
EndEpisode();
}
AddReward(1.0f);
}
@@ -267,6 +271,7 @@ public class AgentController : Agent
discreteActionsOut[1] = 1;
}
// finds distance from agent to closest point on the checkpoint line
float distanceToCheckpoint(Transform checkpoint)
{
var closestPoint = checkpoint.GetComponent<Collider>().ClosestPointOnBounds(transform.position);
@@ -274,6 +279,15 @@ public class AgentController : Agent
return distanceToCheckpoint;
}
// find angle from agent to middle of checkpoint line.
float angleToCheckpoint(Transform checkpoint)
{
Vector3 checkpointDirection = checkpoint.localPosition - transform.localPosition;
float angle = Vector3.Angle(transform.forward, checkpointDirection);
return angle;
}
// punishment for hitting a wall
private void OnCollisionEnter(Collision other) {
if (other.gameObject.tag == "Wall")