diff --git a/Assets/Scripts/AgentController.cs b/Assets/Scripts/AgentController.cs index 97ed939..9f694da 100644 --- a/Assets/Scripts/AgentController.cs +++ b/Assets/Scripts/AgentController.cs @@ -90,8 +90,6 @@ public class AgentController: Agent // transform.position.y, // transform.position.z + rng // ); - - } @@ -170,17 +168,11 @@ public class AgentController: Agent totalReward -= 0.0018f; 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); - // Use that to calculate how much torque is available - // (zero torque at top speed) float currentMotorTorque = Mathf.Lerp(motorTorque, 0, speedFactor); - // …and to calculate how much to steer - // (the car steers more gently at top speed) - float currentSteerRange = Mathf.Lerp(steeringRange, steeringRangeAtMaxSpeed, speedFactor); // Check whether the user input is in the same direction diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 5b0b9f1..9469708 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -43,26 +43,15 @@ public class PlayerController : MonoBehaviour float vInput = Input.GetAxis("Vertical"); float hInput = Input.GetAxis("Horizontal"); - // Calculate current speed in relation to the forward direction of the car - // (this returns a negative number when traveling backwards) + float forwardSpeed = Vector3.Dot(transform.forward, rigidBody.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); - // Use that to calculate how much torque is available - // (zero torque at top speed) float currentMotorTorque = Mathf.Lerp(motorTorque, 0, speedFactor); - // …and to calculate how much to steer - // (the car steers more gently at top speed) - float currentSteerRange = Mathf.Lerp(steeringRange, steeringRangeAtMaxSpeed, speedFactor); - - // Check whether the user input is in the same direction - // as the car's velocity + bool isAccelerating = Mathf.Sign(vInput) == Mathf.Sign(forwardSpeed); bool isStopping = vInput == 0; // range