I am having some trouble calculating the static friction for a tyre.
I have a method that takes works out the amount of force to apply to a point to generate a specific amount of force and torque. If i feed it the accumulated force (+weight force) and torque of a rigid body, and the point of contact between the ground and the wheel, I can then apply the inverse of that force projected onto the ground plane to cancel out any of the force applied to vehicle.
This works for keeping the vehicle stuck on slope, as it matches the force of gravity, but it doesnt take into the momentum of the vehicle (so if the vehicle is already sliding, it will continue to slide). I then decided to feed the method with the vehicles momentum in place of force, and the angular momentum in place of torque, both divided by the timestep, and then if i apply this force at the contact point, the vehicle immediately stops. This is very stable too, even at 30hz fixed update, it applies the amount required to stop the vehicle and no more, there is no jitter etc.
The problem i have is that this doesnt account for the rolling of the tyre, so the wheels always behave as if they are locked, and attempt i have made to incorporate this into the calculate has resulted in very unstable behavior.
To be clear, I am not asking how to calculate friction forces for tyre like pacejka or anything like that. I am trying to find the maximum amount of force that could ever possible be applied so i can clamp the friction. Basically, I want to be able to set a tyres friction essentially to infinity, and the vehicle should basically behave like a train on rails, without any slip on the tyres (a small amount of slip will occur as the simulation cant be perfect of course), instead of jittering or pinging the car off to infinity
The method looks this:
public static Vector3 ForceAtPoint(Vector3 linearForce, Vector3 torque, Vector3 worldPoint, Vector3 worldCentreOfMass)
{
Vector3 comToPoint = worldCentreOfMass.PointTo(worldPoint);
// Calculate the force that when applied at 'point' will generate the given torque
Vector3 forceDueToTorque = Vector3.Cross(torque, comToPoint) / comToPoint.sqrMagnitude;
// The total force is the sum of the linear force and the force due to the torque
Vector3 totalForce = linearForce + forceDueToTorque;
return totalForce;
}
(The PointTo() method is simply the displacement vector from v1 to v2 (v2 minus v1))
EDIT: I was originally using the method shown in the Just Cause 4 Tire Dynamics GDC video (
) but was having issues with it. I have just realised my mistake. It uses the inertia tensor from the rigidbody, but needs it in world space, where I was passing it in locally. It now works very well for lateral friction, but still doesn’t work perfectly for longitudinal (or angular) so am still hoping for a solution.