# How can I simulate locking or limited-slip differentials in Unity?

I have been developing a racing game in Unity for a few months and I can't find any information on how to simulate a car differential.

Right now I just split the torque generated by the engine 50-50 to the wheels, but it's a really bad implementation. Can anyone give me at least a lead on what to do or look for?

• Do you want to aim for realism or just letting the car cut the corner sharper than it should be possible? Commented Apr 20 at 20:09
• You are asking explicitly about a locking or limited slip differential, if it is not 50-50 distribution of torque. I've edited the title to match. Commented Apr 21 at 13:26

## 1 Answer

Disclaimer I am not a physics buff, and this answer simplifies by ignoring ideas such as traction, actual power loss at the wheel, etc. But this is for learning purposes, so it should suffice.

I assume a locking differential because you are asking about varied power distributions, which implies your game has offroad driving, and that is what locking differentials are for. They allow any power distribution 0-100, 100-0, 50-50, or anywhere in between, which regular open differentials do not. Note that we are going to use float values throughout this example.

Calculating unit totals using unit interval fractions

OK, you want to know how to distribute power in ways that is not just 50-50 (0.5 to 0.5 ratio). So lets work this backwards. Take a look at this:

totalEnginePower = 90.0 //let's say kilowatts
wheelPowerLeft = 54.0
wheelPowerRight = 36.0

90.0 = 54.0 + 36.0 //kilowatts, total = wheel + wheel

//or, if you divide all terms of the above equation by totalEnginePower (90)...

1.0 = 0.6 + 0.4 //unit = fraction + fraction


We're going to use this last line -- called a unit interval calculation because it adds up nicely to 1.0 -- as our format for solving the problem.

The remaining question is "how do we get the two wheels power ratings to add up to 1.0 (or 90)?" So let's look into that.

//enum
LEFT = 0
RIGHT = 1

wheelPower = [];

wheelPower[LEFT] = getPowerRatioAppliedAtWheel(LEFT)
wheelPower[RIGHT] = getPowerRatioAppliedAtWheel(RIGHT)


In fact, for getPowerRatioAppliedAtWheel() we should use resistance and other factors, e.g. tyre type, surface looseness / wetness etc. to get your lossOfPowerAtWheel. But OK, I we leave that to you to calculate for your game. Anyway, it should return a value between 0.0 and 1.0 (a unit interval value), so that the below calculations can work.

Now, these two resistances could be any pair of values, such as:

• 0.7 and 0.4
• 0.0 and 0.23 or
• 1.0 and 0.9.

Notice how none of these pairs sums up to 1.0! Very rarely will they sum up to 1.0 as-is.

Let's say we get back 0.7 and 0.9 as resistances for the left and right wheels respectively. We need to adjust these so that we get a unit total of 1.0:

totalPowerDivisor = 0.7 + 0.9 = 1.6
wheelUnit = wheelPower / totalPowerDivisor


Therefore:

wheelUnit = [];

wheelUnit[LEFT]  = wheelPower[LEFT] / totalPowerDivisor // 0.7 / 1.6 = 0.4375
wheelUnit[RIGHT] = wheelPower[RIGHT] / totalPowerDivisor // 0.9 / 1.6 = 0.5625

//consequently, the two results will always add up to 1.0
//(try it yourself for any pair of wheelPowerLoss values)
let sum = wheelUnitLoss[LEFT] + wheelUnitLoss[RIGHT] // 0.4375 + 0.5626 = 1.0


This last line is the unit power distribution (unit because it sums to 1.0). There are 2 addends because you have 2 wheels. Imagine 8 wheels, you'd need 8 terms all summing to 1.0 (in reality an 8-wheeled vehicle would probably use 4 differentials).

It is trivial to convert this to actual power per wheel, based on your engine's total power rating:

0.4375 * 90 = 39.375 kilowatts
0.5625 * 90 = 50.625 kilowatts

39.375 + 50.625 = 90.0 kilowatts


I'm you can figure out how to implement this into working code after further thought.