Looks pretty nice so far. Fairly similar to what I was doing.
The key value really is the one you have defined near the start though
while 1
{
set $car maxtorque factor 0.5
Ideally you want to have that factor a variable too. That is the torque factor at min boost, and you move to 1.0 at max boost.
That figure is in a sense the responsiveness of the engine off-boost. A 1000bhp Skyline might need 0.3 for that factor, so until it gets some boost it's cutting out loads of torque.
A car like a 135i BMW that runs quite mild boost for only 270 > 300bhp vs the same family engine from NA > turbo, might have the torque factor at 0.8 for example, so 80% of the torque is always there, 20% comes with some lag...
So imo, you need to define that as a variable for users to tune.
The second problem is that the turbo is quite independent of engine rpm. A higher gear and slower progression through the revs usually gives boost sooner and at lower rpm. I think rpm are tempting to use in there, but are probably best left out altogether.
The last issue is that when you define your torque curve, you have a low-rpm torque gap where the turbo can't ever get fast enough in real life. The problem is your 'script' turbo is cutting torque all over, so the low-end will feel even more laggy while in real life it might not be at all.
So we need a way to compensate for that too. We could do with saying something like the initial max torque factor is adjusted by engine rpm and a pair of variables which it interpolates between, say for a 1000bhp Skyline a curve might build up from 3000rpm and hit peak at 4500rpm, so you would have max torque factor at 1 from 0-3000rpm, and then from 3000-4500rpm have it change to the new factor of say 0.3, so it gets laggy.
Personally I think it's too complicated. Mine looks a bit like that now, but the reason I have too many variables is I'm chasing around problems which are generated by the above issues. Those above issues are more real ways to get a realistic turbo behaviour.
I'm aiming for a list a bit like this for user inputs.
spinup (rate it spins up)
spindown (rate it spins down)
boost (the value that moves around and defines how much instant torque you get)
boost threshold (where boost starts being added)
peak boost (where boost stops building up)
In theory that should be enough.
You can grab the turbo max speed as a notional amount from 1-boost... then you can just use spinup/spindown values in the appropriate magnitude range to work with the kinds of values that gives you (between 0 and 1)
I realised last night that having min/max speed defined, and spinup/spindown, just resulted in values that could all be worked up and down with the same end result.
Ie, half spinup, half spindown and half the max speed and it was the same for all intents and purposes. Max speed seems to be pointless to set by another user input variable. The magnitude of the variables is kinda irrelevant, what seems to matter is that they are 'tangible' variables that make sense wrt the real system
Looks like you were thinking the same things as me hehe, but the issue last night for me was the lag was all over, and on high boost engines (ie, not much torque at full throttle off boost vs on boost like a 1000bhp skyline) the low-rpm part of the torque curve was horrible... you do need a way to turn off the turbo effects there.
The only alternative is to add torque back in, BUT, that is dodgy because it's not how the system works irl. Imo, as you deviate from real behaviour logic, the further from reality it will react.
Hmmm
Dave