- Home /
Wheel Collider motorTorque
Hey Guys,
I am having trouble with the motorTorque and wheelRPM. Everything seems to be working fine until I have to apply the force to the actual motorTorque on the WheelCollider. I have an AnimationCurve to get the Engine Torque corresponding to the current Engine RPM. I change it to wheelTorque: (EngineTorque x gearRatios[currentGear] x finalDrive). When I apply it to the WheelCollider.motorTorque it seems to be good but the WheelCollider RPM keeps getting higher. It should stop at around 520RPM but it goes up to 45,000RPM and keeps going.
//Get the RPM of the engine.
currentEngineRPM = throttleInput > 0 ? Mathf.Lerp(currentEngineRPM, maxEngineRPM, Time.deltaTime) : Mathf.Lerp(currentEngineRPM, idleRPM, Time.deltaTime);
wheelRPM = currentEngineRPM / gearRatios[currentGear] / finalDrive;
//Use the RPM to get the corresponding Torque Nm
engineTorque = torqueCurve.Evaluate(currentEngineRPM);
//Change engineTorque Nm to wheelTorque N
wheelTorque = engineTorque * gearRatios[currentGear] * finalDrive;
//Calculate Speed
float wheelCircumferenceMiles = 2 * Mathf.PI * wheelRadius / 63360;
float MPM = wheelRPM * wheelCircumferenceMiles;
Speed = (MPM * 60) * 1.609344f;
foreach (WheelCollider wheel in _driveWheels)
{
wheel.motorTorque = wheelTorque;
}
All the code seems to be working fine when I Debug.Log the variables. But when I Log the WheelCollider.rpm it's higher than the wheelRPM variable(which is correct) used to compare it with.
Thanks in advance for any help or suggestions.