Traction Curve Merge
Along with my changes to the suspension model where to refine the traction model for https://github.com/Murph9/RallyGame
The previous model uses a simplifed Pacejka Magic Formula as noted in a previous blog post. That only covers each direction individually, I found a good blog post (http://phors.locost7.info/phors25.htm) which basically describes the math behind how it all has to work. The summary is that you want each direction to contribute to the maximum slip irrelevent of whether what its maximum slip value is. This can result in a maximum which is actually ellipse shaped. This math mostly goes over my head, but the graphs below should help.
So trying to implement this I found that it was very hard to tell whether or not the combined values where actually combining successfuly - although running the game and seeing the car accelerate in a uncontrolled spin and roll was helpful it didn’t tell me what was going wrong.
In comes the wonderful scatter plot, which I made myself (https://www.murph9.com/scatterplot) which takes in a list of x,y,color and plots it for you. The javascript is available to use if you just copy it from the source.
Basically this comes down to how to normalise each of them based on their maximal value. The math goes like this:
float ratiofract = slipratio/maxLong;
float anglefract = slipangle/maxLat;
float p = FastMath.sqrt(ratiofract*ratiofract + anglefract*anglefract);
fz = (ratiofract/p)*formula(p*maxLong) * susForce;
fx = -(anglefract/p)*formula(p*maxLat) * susForce;
So to explain this:
*fract
lines = fraction comparing the value to the maximal value
p
= combined total maximal value, if equal to 1 the tyre has no more to give. More and we are more slipping than gripping.
f*
= calculate the value for the normalised traction value
Which results in a graph like this:
With this change it feels like a ‘real’ car game, hopefully this helps someone else.
My source for this is at: https://github.com/Murph9/RallyGame/blob/master/src/car/ray/RayCar.java