# Differential programming for a vehicle

I am to a point on my vehicle where, when im going fast and turning, the vehicle acts weird because the inside tires are moving faster than the outside tires. So i need to figure out how to program in a differential but I can't seem to get it working properly so I am here to see if anyone has experience with this.

I have checked online for the physics but that seems to take more info into account than i can supply in my game (like real gravity influence on the vehicle). Currently I use the following logic to determine the differential wheel speeds. I will try to explain as clearly and simply as possible so I apologize if it is confusing or over-simplified, its confusing to me!

Here is what i do: I divide my current turn degree by the max turn amount to get a percentage, I then take that percentage and apply that to a modifier percentage (just a percent i have made up and been tweaking to reduce the number passed to the differential, not sure what this should really be. Engine speed? Velocity?). Then in my differential, I check to see if the vehicle is turning left or right and reduce the speed on one side by x% and increase the speed on the other side by the same x%

I'm certain that my biggest problem is the number i'm making up to reduce the turn percent but I cant tell what to put there. I know that directly passing the turn % to the differential (say, 40%) would reduce one side by 40 and increase the other by 40 and that is clearly not right.

I have access to the engine speed, transmission, each wheels axle speed, torque, vehicle velocity, etc but I am not sure which of these i should take into consideration when doing this formula.

Maybe I am over complicating it or maybe i am over simplifying it. Any help in understanding this would be great!

• What problems did you really have with the real physics involved? Because gravity is easily obtained (it's a constant that you should just tweak, same goes for vehicle mass etc..) – Roy T. Apr 17 '12 at 20:04
• Well, not really any major problems with the real physics but because I don't really know a whole lot about differentials and (real life) mechanics, the physics went over my head. – Mungoid Apr 18 '12 at 2:16

I really think you should not do it this way and that you should look more into the real physics (see my comment). However I can tell you why your current approach doesn't work. (Too long for the comments so I'll just post this as an answer)

Let's first explore what happens (you've probably done this yourself already).

The sitation is basically as in the picture above, but let's simplify the numbers a bit:

Say the car C is 2 meters wide and has a minimum turning circle of 5 meter. I now steer full left. The front left wheel now follows a circle with a diameter of 5 meters. The front right wheel now follows a circle with the diameter of 7 meters. Completing one full circle will have the left wheel travel 10*pi meters. The right wheel travels 14*pi meters. Now say that the wheels of C all have the same size, and that the circumference of the wheels is 0.5*pi meters (yes those are big wheels, but no-one said we couldn't model a monster truck!) The differential will have to make sure that for every 20 rotations of the left wheel the right wheel rotates 28 times in order for none of the wheels to slip.

So you could now say that the diff-% should be tweaked, say for full left it should differentiate +40%, and let's just lerp this to full right -40% and then we're golden?

Unfortunately, as you've seen, this doesn't work. Let's find a general formula for the differential in this car. Here x is the desired turning circle.

left wheel distance: x*pi meters
right wheel distance: (x+2)*pi meters:
left wheel rotations: x*4
right wheel rotations: (x+2)*4


I would argue that the diff should work at the fraction ((x+2)*4 / (x*4)) [*]. (Times 100% if you want it in percentages) Let's plot that:

As you can clearly see this function is non-linear. So just having the differential depend linearly on how much your steer to the left or to the right is never going to work.

Now I see that it's tempting to just use the above formula but I think it's probably best if you don't for the reasons described above :). Also you will need to implement 2 differentials unless if your steering involves all four wheels, which makes it even more difficult to implement, see the 1st picture again.

[*]: which we can simplify: (x+2)*4 / (x*4) => (x+2)/x

• I am not at my work computer to try this out but I have a strong feeling you are right on all points! And you aren't too far off about the monster truck thing. Its a piece of heavy machinery for a simulator so the wheels are about 2 meters in diameter. Originally I thought I would be able to 'cheat' as i just need to keep the wheels on the ground but I think this will make it much more accurate. I'll run the numbers tomorrow and let you know. Thanks! – Mungoid Apr 18 '12 at 2:10
• Yep, your post pointed me in the right direction. I had tried my own version of the math you gave but apparently I was doing it a bit wrong. Thanks for the guidance! – Mungoid Apr 18 '12 at 13:50