probably broken car controller
This commit is contained in:
@@ -10,6 +10,8 @@ public class carcontrolv2 : MonoBehaviour
|
||||
public float steeringRange = 30;
|
||||
public float steeringRangeAtMaxSpeed = 10;
|
||||
|
||||
public float autoBrake;
|
||||
|
||||
WheelControl[] wheels;
|
||||
Rigidbody rigidBody;
|
||||
|
||||
@@ -50,6 +52,12 @@ public class carcontrolv2 : MonoBehaviour
|
||||
// as the car's velocity
|
||||
bool isAccelerating = Mathf.Sign(vInput) == Mathf.Sign(forwardSpeed);
|
||||
|
||||
bool isStopping = vInput == 0; // range
|
||||
|
||||
bool isBraking = vInput < 0 && forwardSpeed > 0;
|
||||
|
||||
Debug.Log(vInput);
|
||||
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
// Apply steering to Wheel colliders that have "Steerable" enabled
|
||||
@@ -67,12 +75,19 @@ public class carcontrolv2 : MonoBehaviour
|
||||
}
|
||||
wheel.WheelCollider.brakeTorque = 0;
|
||||
}
|
||||
else
|
||||
|
||||
if (isBraking)
|
||||
{
|
||||
wheel.WheelCollider.brakeTorque = Mathf.Abs(vInput) * brakeTorque;
|
||||
//wheel.WheelCollider.motorTorque = 0;
|
||||
}
|
||||
|
||||
if (isStopping)
|
||||
{
|
||||
// If the user is trying to go in the opposite direction
|
||||
// apply brakes to all wheels
|
||||
wheel.WheelCollider.brakeTorque = Mathf.Abs(vInput) * brakeTorque;
|
||||
wheel.WheelCollider.motorTorque = 0;
|
||||
wheel.WheelCollider.brakeTorque = Mathf.Abs(vInput) * brakeTorque + autoBrake;
|
||||
// wheel.WheelCollider.motorTorque = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user