This commit is contained in:
2024-04-23 10:45:45 +02:00
parent 89993829ba
commit f2ae69b28f
16 changed files with 809 additions and 912 deletions

View File

@@ -20,8 +20,8 @@ public class AgentControllerV7 : Agent
public float steeringRangeAtMaxSpeed = 7;
public float autoBrake = 100;
WheelControl[] wheels;
Rigidbody rigidBody;
public List<GameObject> checkpoints;
Rigidbody rb;
Vector3 startPosition;
Quaternion startRotation;
int currentStep = 0;
@@ -36,10 +36,10 @@ public class AgentControllerV7 : Agent
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody>();
rb = GetComponent<Rigidbody>();
// Find all child GameObjects that have the WheelControl script attached
wheels = GetComponentsInChildren<WheelControl>();
startPosition = transform.localPosition;
startRotation = transform.localRotation;
@@ -64,8 +64,8 @@ public class AgentControllerV7 : Agent
// reset car
transform.localPosition = startPosition;
transform.localRotation = startRotation;
rigidBody.velocity = Vector3.zero;
rigidBody.angularVelocity = Vector3.zero;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
}
public override void CollectObservations(VectorSensor sensor)
@@ -98,9 +98,9 @@ public class AgentControllerV7 : Agent
// relative Velocity
Vector3 velocity = new Vector3(
rigidBody.velocity.x,
rb.velocity.x,
0,
rigidBody.velocity.z
rb.velocity.z
);
Vector3 relativeVelocity = Quaternion.Euler(0, -carAngle, 0) * velocity;
@@ -133,7 +133,7 @@ public class AgentControllerV7 : Agent
if (ignoreMentalPain)
totalReward -= 0.0018f;
float forwardSpeed = Vector3.Dot(transform.forward, rigidBody.velocity);
float forwardSpeed = Vector3.Dot(transform.forward, rb.velocity);
// Calculate how close the car is to top speed
// as a number from zero to one
float speedFactor = Mathf.InverseLerp(0, maxSpeed / 4, forwardSpeed);
@@ -218,12 +218,11 @@ public class AgentControllerV7 : Agent
if (checkpintDistance < 0.1f)
{
currentCheckpoint.GetComponent<Checkpoint>().isCollected = true;
stepsSinceCheckpoint = 0;
checkpointsReached += 1;
// If last checkpoint
if (currentCheckpoint == checkpoints[checkpoints.Count - 1].transform)
if (checkpointsReached == checkpoints.Count - 1)
{
AddReward(10f);
EndEpisode();