Upcoming Events

Weekly BMW races on Simracing.GP Other regular AC events on Simracing.GP Weekly GT3 Sprint Races on Simracing.GP Weekly GT4 Sprint Races on Simracing.GP Daily WTCR races on Simracing.GP

A question about differentials

Hey all, I'm new to this forum and I recently got interested in Racer again, was much more of a player back then, now I started playing around with car making.

Back then, I was pretty much disappointed by the fact you could only have 2 wheel driven cars, no matter if FWD or RWD, because you could just have one differential powering a single couple of wheels. You could make all wheels powered, but just one axle could have a diff (using the trick explained on the Racer site itself).

Then after some research (on this forum as well), I found a script which kind of "hacks" 4WD into a car, but it's a .rsx (+ a compiled .rcx) file (now that I learned C at university, it's somewhat easier for me to understand those files since the syntax is pretty much similar), the one for the Gallardo. I think this script is quite popular on this forum since I saw it being used, with some addition, on some other cars as well. Plus, the script is something like a torque-transferrer which controls torque vectoring on the four wheels, not a fixed 4WD bias system, which is the thing I'd like to implement. Also, obviously this script isn't mine, I'd like to use as many "personal" parts as possible on my cars, just to avoid copyright infringements and stuff.

BUT. I found out that since a version of Racer I can't recall (now I'm using the latest 0.9.0. RC10) you can specify "count=" in the differential section, so I thought:


Is it possible to have a dual-diff 4WD setup using, for example, "count=2" and making the first diff's output to 0 and 1 (i.e. front wheels) and the second one's output to 2 and 3 (i.e. rear wheels)? Also, if possible, what's the recommended type of diff I could use? Viscous ones or even LSDs can be used for such an application? Should I use the same ratios for front and back (I guess yes, since in real life there's just ONE final drive gear)?

Thanks in advance :)
Racer still only supports a single differential, despite the diff.count parameter being present. All current AWD scripts that I'm aware of (including the Gallardo's) fundamentally use the same hack as described on racer.nl. The difference is that they add a layer of complexity by dynamically varying the torque split through adjustment of engine.max_torque and wheelx.power_gearing, based on whatever criteria the script author sees fit. There are some issues associated with this approach, as engine response is affected for example.
Thanks for the reply, Cosmo :)

Engine response is affected, yeah. In the Gravedigger WIP thread though I found out that with a couple more lines of code, you could restore the engine response when the car is sitting still or moving slowly (in fact, I'm using those lines in my AWD script too, I'll give credit, no worries.).

Okay then, seems like using the Gallardo script is the only way to implement a decent "real time AWD" system, which is what I was looking for in the car I am building right now. I guess it works quite fine now, but I have one more question:

How am I supposed to set the non-diff'ed wheels' power_gearing value (in car.ini, not in the script itself) if I am using the dynamically adjusting AWD script?

Thanks :)
The Gallardo system is ok for mostly rear biased awd systems, with some front torque sent there if the back end tyres are spinning quite a bit.

So it works nicely for say a 911 Turbo, Gallardo, Sierra XR4x4 kinda cars, all with viscous coupling type centre diffs and a rear bias.
It's probably less good for say VAG stuff like Audi S3 or Golf R32, or Mitsubishi Evo etc.

Really what is important is tweaking the coefficients and watching the slip ratios of the wheels in driving, and tweaking the values to get the slip ratios doing what you want them to do, and as always, good old road testing to get it feeling good.

Given right now the AWD system we have isn't really 'proper', then going on at the wheels needs and the dynamics balance you want is more important than trying to strictly adhere to 'real' values that simply won't have any relevance with Racer's current awd system.

When I created that script for the Gallardo it was all about roughly copying what the real car's awd would do at the wheels, and mostly actually just making it drive nicely and reacting in a nice way for road sports driving... the actual mechanics are probably quite different in some areas, especially in areas where the real cars ESP/electronics are managing torque biasing too to quell under-steer, or control traction etc.

If you give Cosmo and I some ideas about the awd system you're trying to implement we can probably help you some more.


Well yes, a viscous center diff is what I'd like to implement, but my idea is a system that normally sends a 50-50 torque split to the wheels and alters it just if one of the tires (or axles) is skidding more than the other(s).

If it ain't possible, then I'd just stick with a 50-50 fixed bias with no center diff (just a real rear diff and a "faked" front one via script).
The Gallardo system is essentially that, with a static differential torque split (fudged but as good as it can be done with this system), and then the split is managed depending on the front/rear axle speed differential wheel speeds.

In theory you can just set it up for a 50:50 split and then tweak the other coefficients to change it from there.

The script notes kinda describe how it works, but the script logic itself should make sense if you spend half an hour with it understanding what it does.

The primary problem with a 50:50 static split is that the engine torque is 50% which means free-revving response is quite wrong etc.
There are ways around that depending on where you want to compromise I suppose.


Oh, so that means I could just keep the script as it is, great then!


To restore the free-revving response I used the method suggested in the Gravedigger WIP topic: a few more code lines that tell the script to give 100% torque if the car's speed is under a reasonably low level.

Should be this:
    if $rot_front_diff and $rot_rear_diff < 4
        $maxtorque = 100


My very last question for such an AWD system: Do I need to specify a power_gearing value for the wheels not attached to the "real" diff (i.e. the front ones)? If I need to, which value should I use?
As you can see in the Gallardo's respective files, all the script does in the end is to constantly modulate the engine's max_torque and powergearing for the two wheels which are not connected to the differential. You assign a value to powergearing in car.ini, but it can be a generic one, because it is overwritten with every iteration of the script's logic. Perhaps a fail-safe setting that assures a certain static split in case the script isn't working for some reason, rather than completely random.
Alright then, for the "backup" value I used the formula from "Faking 4WD" at racer.nl:

power_gearing=differential.ratio*torque split/2

Now, given that my car has a 3.64:1 diff (using values from a T5 Ford/Cosworth transmission and driveline, gotta give my car some Sierra-ish specs) and that it (normally) has a 50:50 torque split, it should be:


Am I right? :)
Sierra ish specs?

If it's the usual awd system fitted to that era of road going Fords I think it'll be 66% static torque to the rear.

If it's something else then ignore me :)

I think that maths is right. Try it and see what happens.


Also, the low-speed idle torque thing, I'm not sure that is the best way to achieve what you need.

It might be better to do something based on the clutch, or selected gear, or maybe at very very low road speed (sub 1km/h) hard set the torque split to 100% rear.

Otherwise with your system you may end up with more total torque by say 30-50% more than real life, until the differentials are spinning over 4 rad/s, which might be quite fast.

Again it depends on your needs, but I'd be more tempted to do:

when under 1km/h, set final bias = 1

or whatever it is to get the script to ignore what's been calculated, and set the bias to 100% to the proper differential and set the engine torque to maximum.

Obviously you'd set this just before the values are set for the power gearing and max torque in the script.

Indeed, given how the XR4x4/Sierra type awd system works, I'd say that is more in line with how it probably felt in real life... it was really easy to get mine to spin the rears and feel more rwd at first off the line, until you really noticed the fronts where working away.
I said Sierra-ish specs but I'm just referring to the engine and transmission ratios -- I always wanted the car to be a 50:50 torque split from the very beginning. Plus, it's gonna be way lighter than a real Sierra, roughly a ton or so.

The power_gearing value works just nice as it is.

Also switched to a viscous rear diff, made the car much nicer to drive (it had a locked one, what the hell?).

Well... I tried hard-launching my car lots of times and it never ever felt RWD-ish at all with my actual setup -- I get uniform 4-wheel tire smoke and a pretty fast take-off with almost no wheelspin...

About the adjustments in the AWD script: what about just changing the lines I quoted to something like this
if $rot_front_diff and $rot_rear_diff < 0.1
    $maxtorque = 100
I'm kind of a null, if only I had more time to investigate into the script's lines (having an exam on Monday at uni)...

EDIT: Tried those code lines, kind of better. BUT. I found out a pesky bug coming out from this way to implement AWD... Front wheels have a faked diff, okay that's cool. But it's a locked diff, and that completely ruins the car's behaviour, especially when cornering after a braking zone (front wheels tend to pull the car forwards no matter the steering angle, causing some non-recoverable understeer). And I guess this gets even more pronounced if the front wheels have lots of torque -- that means, the worst case happens in my case, i.e. 50:50 torque split.

Guess I'm just going to leave this car RWD until (eventually) a new Racer version with multi-diff support comes out (is Ruud still developing Racer? v0.9.0 RC10 is more than one year old now...). It became very fun to drive with a viscous diff and RWD, without any other changes.
Last edited:
In that script there is already this:

//remove low-speed noise, just run static torque split under this speed (4)
if $rot_front_diff and $rot_rear_diff < 4
$diffbias = $staticbias

So in theory you could just set something like that near the end, and just override the final bias value.

If you don't set the final bias value, then the power_gearing will not be cut, so you'll have a powerful engine AND front wheel drive, so too much total torque.

As per front wheels spinning away, yes that isn't great. Their speeds get very high.

Really you need to tweak this code to do something more in line with a fixed torque split but a viscous coupling.

Ie, lets say when the differential gets high, you get lock up, so as a fudge we can send torque to the rear so the fronts don't over-spin, and vice versa, but always returning to a near static 50:50 torque split when there is no differential.

Something like this works ok maybe.

// AWD script for Gallardo and other cars with similar awd system.
// The real car uses an in-line viscous coupling with a driveline set up with a static front/rear differential to give ~ 95% rear torque and 5% front
// In this case we set the specs for the power_gearing 'hack' to work, along with the static bias of the torque split
// Because of the in-line nature of the viscous diff in this case, we can roughly say that with a large front/rear differential the more locking we see
// But because the front wheels can 'fly away' way beyond the real diff/engine speed due to the power_gearing AWD hack, we also send torque back to the rear
// if the front/rear axle differential gets large (to the front)
// So basically, lots of rear slip, send torque to the front (up to 50% in theory, though it never reaches that in most normal situations), when fronts start
// slipping too fast, as they will with lots of torque, then trim the torque to them and send it back to the back. Ultimately the car is as 'fwd' as it can be
// without the front pair spinning a small percentage more than the rear axles speed (though in real life this may occur any way due to inertia and varying rear
// wheel speeds in transient conditions)
// This is as good a fudge as we can get and in my view drives nicely enough for this type of AWD installation.

rcar $car=get scriptowner car

float $finaldrive = 4.529
float $staticbias = 50

float $slipratiof
float $slipratior

float $rot_front_diff
float $rot_rear_diff
float $bias_ratio

float $locking_factor = 1200
float $ramp = 0.05

//How often to run the script (ms), throttles the ramp rate above too. A longer duration means faster FPS for now.
float $frequency = 5

float $powergearing
float $diffbias = $staticbias
float $finalbias = $diffbias
float $maxtorque

float $slipfront

while 1
    //Calculate the diff bias
    $rot_front_diff = sqrt (pow((get system "car0.wheel0.rotvel") + (get system "car0.wheel1.rotvel")) to 2)
    $rot_rear_diff = sqrt (pow((get system "car0.wheel2.rotvel") + (get system "car0.wheel3.rotvel")) to 2)
    $bias_ratio = ($rot_front_diff - $rot_rear_diff) / ($rot_front_diff + $rot_rear_diff)

    $diffbias = $staticbias + ($bias_ratio * $locking_factor)
    if $diffbias < 0
        $diffbias = 0
    if $diffbias > 100
        $diffbias = 100
    //remove low-speed noise, just run static torque split under this speed (4)
    if $rot_front_diff and $rot_rear_diff < 4
        $diffbias = $staticbias
    if $finalbias > $diffbias
        if $finalbias > 0
            $finalbias -= ($ramp * $frequency)
            $finalbias = 0
        if $finalbias < 100
            $finalbias += ($ramp * $frequency)
            $finalbias = 100
    $powergearing = (($finaldrive * (100 - $finalbias)) / $finalbias) / 2
    $maxtorque = $finalbias
    //Set the diff bias
    set $car wheel 0 powergearing $powergearing
    set $car wheel 1 powergearing $powergearing

    set $car maxtorque factor ($maxtorque / 100)
    wait $frequency

I was just playing with this for a 50:50 split like an Evo VII the other day.

So all it's doing is just sending torque away from the faster axle but aiming to send a 50:50 split when the two axle speeds are the same.

So unlike the Gallardo which is rwd with a slight differential in axle speeds to effect a torque split in reality, with a viscous coupling that can also lock, it'll never go more than 50% front torque.
But the Evo being a fixed 50:50 split must be able to visco lock either way I think. Maybe actually it just has a visco to the rear diff, so the fronts will spin 50%, but if they try over-spin vs the rear then more torque goes to the back?
So maybe this system isn't perfect, but you can tweak it to do something more like that maybe.

Also I tweaked some coefficients a bit to make it a bit faster to react, and also change more dramatically to kill the Evo VII understeer nicely.

AWD is really complicated and there are so many variants, so I'm not sure Ruud will ever really offer us an AWD system properly. In this case the Evo VII AWD is way complicated, but what I've done at least gives it some 'feeling' like reality.

I do know Ruud coded the Onyx (now Panthera?) system to be able to do complete independent physics systems in Racer, so perhaps one day in a Free Racer version we can just add our own AWD systems over the top of the current Racer system.

I've not heard from Ruud for ages, maybe he's still developing Free Racer, I'm not sure.

It'd be good to hear from him and get some updates indeed!


Tested it. Works quite nicely power-delivery-wise, still having that "pulling" effect from the front wheels when heavily decelerating (e.g. downshifting to 1st gear for a tight hairpin), I bet it's unfixable with the current way we have to implement 4WD. Oh, and it makes a lot of smoke from the front wheels and I can't figure out why -- engine RPM don't rise that much so it couldn't be power-wheelspin. I literally copypasted your script and just changed the differential's value to the one my car uses... okay I start thinking Racer's engine is hating me or so xD

I'm now linking you the car (Mediafire link because it's still in progress) -- oh, I'll also unveil you what it is. It's (gonna be) a high quality rework of a car from the '99 R/C car game "Re-Volt" by Acclaim. Right now it's just a HD (2048x) retexture of it with a slightly higher-poly model, should make 3D windows, lights and grills for it, there's a lot to do, and most thingies are borrowed from a BMW 323i I found on tracciontrasera (gonna change them as well, still crediting the original car's author for those). At least I made the dials and most of the materials, as well as the torque curve. Needs sounds too.

If you'd like to give it a look, go on :)

Last edited: