Ruud is right, you will need what he proposes to get engine braking
working in your sim, but you are also correct that when throttle=1, the
torque output will be the max torque at whatever rpm the engine is
running at. It looks from another of your replies that you are
calculating the engine rpm from the wheel rpm, which is correct, but if
the wheels are off the ground the engine *will* redline pretty quickly.
If your engine is redlining almost immediately with the wheels on the
ground and with friction there, then I think you're doing something
wrong with the torque when it gets to the wheels. Sorry if that's not
the case, but if it is, then I'll write this out. Even if it doesn't
help you it might help someone. I can't really tell what you are doing
or aren't doing so I will quickly trace out the steps so that you can
compare your code with this algorithm (this will be quite simple).
The engine has an rpm, you have a throttle position, and from these two
things you calculate a torque value, I think in your code you say
input.Throttle * GetMaxTorqueAtRPM(currentEngin-eRpm). You could even
just make it a scalar for now, ie torque = input.Throttle *
CONST_TORQUE and come back to fix it later, but if you already have a
GetMaxTorqueAtRPM() function that you know works then use that.
This torque is passed through the gearbox and the diff and must be
multiplied by those two ratios, in your code, torque *
gearbox.Ratio * DifferentialRatio. This gives you a torque at the
wheels.
This torque has to produce a forward force at the wheels. To use a
decent tyre model, you would use this equation T = MoI * aa, torque =
moment of inertia * angular acceleration. This is a conversion of F=ma
into the rotational domain. Then you would integrate to get a new
wheel angular velocity, compare that to the free wheel angular
velocity, get a % difference, put that into your tyre model and get a
forward force [1]. For the time being, ignore that, lets assume 100%
grip, so just take the torque and divide it by the radius of the wheel
to get the forward force produced at the contact patch.
Subtract from this the resistance forces- air resistance and rolling
resistance to get a total forward force on the car. Apply this to the
chassis, F=ma to get an acceleration for your car, integrate it to get
the new car velocity.
this is a speed not a torque so as you send it back up the drivetrain
you still multiply by the gear/diff ratios instead of dividing as you
would for a torque, so take the wheel rotation speed, multiply by diff
ratio and gear ratio, that's the new engine rpm.
A couple of points. If you use this method to start with, the engine
revs should be very very low when the car starts moving, at an rpm
which would mean stalling in real life. That's because we assume 100%
grip of the tyres. If this works, you should work out the angular
velocity of the wheels from the engine torque applied to them and the
frictional forces from the road, as I said in [1]. That means you
don't have to calculate it at [2], you will already have it. This will
allow you to rev the engine and spin the wheels, you'll probably use
Pacejka to do tyre stuff to start with, the wheels will spin and the
revs will rise like in real life. Start simply though.
Make sure the basics work before complicating, writing stubs like this
float GetMaxTorqueAtRPM(float rpm)
{
return 300;
allow you to test things, and later you can rewrite this function body
to actually get a properly calculated value from the rpm value.