Tire Simulation

I’ve been working on a realistic tire simulation for a few days, mainly converting the formulas found here to Unity. The code I have written so far can be found here: Google Code Archive - Long-term storage for Google Code Project Hosting.
For the most part, it is successful (pretty surprising considering I have no idea what’s going on with the formulae), but I’m having trouble calculating longitudinal slip and slip angles using the methods in the paper. So my question is: how do I correctly find the angular velocity of the wheel and speed of the axle? I have not been able to find/use these correctly.
Any tips?

P.S: I would find it very helpful if a Mathf.Sqr() function was introduced. It was pretty frustrating to try to find where to add ,2 as the second argument to the Pow function.

I’m glad to see someone else is working on a more realistic car model as well :slight_smile:

The slip angle is equal to the arc tangent of Vy/|Vx| where:
Vy = lateral speed in the contact point with respect to the road plane (ground velocity).
Vx = longitudinal speed of the contact point with respect to the road plane (ground velocity).

The longitudinal slip (K) is equal to (-Vsx/Vx) where:
Vsx = longitudinal speed of the contact point with respect to woorld coords.
Vx = (see above)

Some code (not tested, since the last time I was worked on my implementation I was in the same boat as you. Since then, I have learned much more, but haven’t had time to really write anything).

var groundVelocity = rigidbody.GetRelativePointVelocity(contactPoint); // the rigidbody belongs to the wheel.
float denom = Mathf.Max(Mathf.Abs(groundVelocity.z), 3.0); // Vx

// Calculate slip angle
var slipAngle = Mathf.Atan(groundVelocity.x/denom) * Mathf.Rad2Deg;

// Calculate longitudinal slip
var speed = (rotational speed of the tire in radians per second) * radius; // I'll let you figure out the rotational speed ;)
var Vsx = speed - groundVelocity.z; // or, I *think* this is equivalent to rigidbody.GetPointVelocity(contactPoint)
// This can normaly be found with longSlip = Vsx/denom;
// But, if you able to the maximum (peak) longitudinal slip you can make this more stable by doing...
var longSlip = 100.0 * Vsx / denom;
var longSlip /= maxSlip;

I’m not positive if I’m calculating the ground velocity correctly because I’m not very confident with local coordinates systems and converting from them to other, ect…

I hope this helps :slight_smile:

We should join forces at some point and combine our efforts :slight_smile: (I’m planning on doing a whole car system - suspension, engine, tire/wheel, ect…)

Heck, we should join forces now. :slight_smile:

Thanks, this really helps. I actually saw your post on the GameDev.net forum; that helped too. Are you using Pacejka?

I suppose the angular velocity would just be

(Mathf.Abs(difference in wheel angles this frame) / Time.deltaTime) * Mathf.Deg2Rad;

to get radians/sec? Note: my wheels don’t have any rigidbodies; it seems so much easier as far as set up goes.

I’m trying this out now, thanks!

Yeah, I am using the Pacejka Magic Formula.
That would probably work to find the angular velocity.

As for the wheel rigidbody, as long as you are able to get the velocity at the contact point (in world coordinates), and then transform that into the wheel local coordinates you should be fine.