Engine RPM/Torque Dictionary lerping?

Hello there, I don’t know why I can’t seem to figure out how to do this.

I’m trying to make a working engine. I understand the concepts and the physics behind it, but I can’t seem to figure out how to get the torque from a certain RPM and lerp to it.

I am using a dictionary to keep track of <RPM, Torque>.
This is what I need to do:

-pseudo-code-

max torque = LookupTorqueCurve(rpm);
engine torque = throttle position * max torque;

I have read an article about vehicle physics in games, and almost every vehicle game I know of creates their engine like this.
This quote sums up what I need to do.

“You could implement the function LookupTorqueCurve by using an array of torque/rpm value pairs and doing linear interpolation between the closest two points.
This torque is delivered to the drive wheels via the gearbox and results in what I’ll call the drive torque.”

I have the necessary variables and lists… I just can’t figure out how to get the closest rpm, then get the torque related to it in the dictionary.

These are my variables by the way:

public Dictionary<float, float> torques;
public float engineRPM;
public float torqueToUse;

Use an Animation Curve to represent the torque curve.

Then get the torque at a given rpm using the Evaluate method:

torque = torqueCurve.Evaluate(engineRPM);

Here’s a good read:

1 Like

Thanks for your response, I’m sorry I’m late… since Holidays are here lol

But thank you for the information, I’ve gotten a working engine setup and running somewhat properly :slight_smile:
I just have to fiddle around with the transmission to get everything running smoothly.

Happy holidays!

1 Like