So, I only need help with like half of this because I found an old post explaining most of it.
I made an engine using the math from [this][1] really old post, and this is the code I have:
float trueRatio = gearRatios[gear] * finalDriveRatio; // current gear * final drive = final ratio
float engineRpm = rearWheels[0].rpm * trueRatio; // wheel rpm * final ratio = engine rpm
float roundedEngineRpm = Mathf.Round(engineRpm / 100) * 100;
float torqueValue = torqueCurve.Evaluate(engineRpm); // get torque for current rpm from curve
float trueTorque = torqueValue * trueRatio;
float force = trueTorque * throttle / wheelDiameter / 2f; // not needed?
float acceleration = force / rb.mass; // not needed?
if (Input.GetKey("w") && gear > 0)
{
foreach(WheelCollider wheel in rearWheels)
{
wheel.motorTorque = torqueValue;
}
}
Now, I have the same problem which OP from that post stated in the replies. The engine RPM is bound to the wheel RPM, so it's impossible to start moving since your wheel RPM is 0 when you're not moving. So how would I instead make it based on flywheel RPM? There wasn't really any good answer for this in that post, and I've tried to figure it out on my own, but I really can't figure out any way to do it.
I'll add a throttle value later but I already have that figured out (just trueTorque * throttle), but if someone can figure out how to add a clutch to this as well that would be nice, because I can't figure that out either...
Thanks!
[1]: https://www.reddit.com/r/gamedev/comments/1320er/math_for_simulating_a_car_transmission_xpost_rmath/
↧