LLLL
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user