I write the code of the car controller. but the torque transmission is processed with a delay. that is, if you release the gas button, the car will continue to accelerate for some time. the same situation with the maximum speed. no matter what I did, it was not possible to fix this delay…
Сode structure is standard:
public class CarController : MonoBehaviour
{
public List<WheelCollider> drivableWC;
public float engineTorque = 1500f;
public AnimationCurve gearsTorqueCurve;
public float verticalInput;
public float currSpeed;
public float currTorque;
public int currGear = 0;
private Rigidbody rig;
private void Awake()
{
rig = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
currSpeed = Mathf.Round(rig.velocity.magnitude * 1.25f * 3.6f);
InputAndUIOperation();
ApplyTorque();
}
private void InputAndUIOperation()
{
verticalInput = Input.GetAxis("Vertical");
}
private void ApplyTorque()
{
currTorque = gearsTorqueCurve.Evaluate(currSpeed / gearsSpeed[currGear]) * engineTorque;
if (currSpeed < gearsSpeed[currGear])
{
foreach (WheelCollider wheelCollider in drivableWC)
{
wheelCollider.motorTorque = currTorque / drivableWC.Count * verticalInput;
}
}
else
{
foreach (WheelCollider wheelCollider in drivableWC)
{
wheelCollider.motorTorque = 0;
}
}
}
}