LLLL
This commit is contained in:
@@ -90,8 +90,6 @@ public class AgentController: Agent
|
|||||||
// transform.position.y,
|
// transform.position.y,
|
||||||
// transform.position.z + rng
|
// transform.position.z + rng
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,17 +168,11 @@ public class AgentController: Agent
|
|||||||
totalReward -= 0.0018f;
|
totalReward -= 0.0018f;
|
||||||
|
|
||||||
float forwardSpeed = Vector3.Dot(transform.forward, rb.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);
|
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);
|
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);
|
float currentSteerRange = Mathf.Lerp(steeringRange, steeringRangeAtMaxSpeed, speedFactor);
|
||||||
|
|
||||||
// Check whether the user input is in the same direction
|
// Check whether the user input is in the same direction
|
||||||
|
|||||||
@@ -43,26 +43,15 @@ public class PlayerController : MonoBehaviour
|
|||||||
float vInput = Input.GetAxis("Vertical");
|
float vInput = Input.GetAxis("Vertical");
|
||||||
float hInput = Input.GetAxis("Horizontal");
|
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);
|
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);
|
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);
|
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);
|
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 isAccelerating = Mathf.Sign(vInput) == Mathf.Sign(forwardSpeed);
|
||||||
|
|
||||||
bool isStopping = vInput == 0; // range
|
bool isStopping = vInput == 0; // range
|
||||||
|
|||||||
Reference in New Issue
Block a user