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;