Simplified car physics?

Started by
7 comments, last by liquiddark 16 years, 4 months ago
Hello, I spent over four hours trying to figure out how to do car physics for an arcade racing game. I managed to do car movement using angle and velocity using polar coordinates to move the vehicle, but that has barely anything to do with real cars. I'd like my cars to slow down while steering and to drift (I think these two are closely related). I have tried to implement spring movement from camera demo here http://www.robthebloke.org/opengl_programming.html, but I was unable to use it in my own game. Do you know of any simple ways (no complicated physics simulations) to implement such behaviour? (I don't want to use external libraries)
OpenGL fanboy.
Advertisement
Slowdown while steering:

Coefficients = abs(sin(theta))i - abs(cos(theta))j,

where i and j are unit vectors aligned with and perpendicular to the long axis of the car, respectively, and theta is the angle of the steering tires relative to the body of car.

Call these A and B, B understood to be negative.

I'll assume you're going to leave kinetic friction effects for last, and just give you the basic static friction effect, which is thus:

Friction = K * N,

where K is the coefficient of friction between the tire and the road surface (this information should be available online), and N is the weight of the car.

For non-sliding motion, the total magnitude of the i + j components of friction must be no more than the maximal force of static friction, ie

SQRT((A . Fa)^2 + (B . Fa)^2) <= K * N

where Fa is the total accelerating force. If this is not the case, you get into sliding friction.

You can calculate the accelerating force by determining the radius, r, of the circle that would be made if your car continued to turn in its current direction, and using the formula

F = m * v^2/r

where v is the car's current linear speed.

In this solution, when you're driving on a straightaway, you have a net friction of zero at the front wheels, and then when you turn into a curve you get that -cos(theta) component, which is the decelerating force.

I haven't tested this solution to see how it performs, but I'm pretty sure the physics is sound.

Once you have the basic friction mechanic down, you can replace the static friction relation

F <= K * N

with the kinetic (sliding) friction one

F = K(v) * N,

where K(v) is the kinetic friction coefficient, which depends on your current speed with respect to the road surface.

For sliding friction you will also have to re-align the coefficients A and B to be relative to the car's velocity, rather than its long axis.

If you implement sliding friction at all four tires, you will have written the basic means by which drifting is achieved.
No Excuses
Thanks! I'll try to implement it.

EDIT: which one is the long axis? :)
OpenGL fanboy.
The long axis is...the long one? I would orient it so that it's the direction from the back to the front of the car. So the calculation I gave is oriented relative to the car rather than the track. But it is a relatively simple transformation from car-relative to world-relative.

In a right hand sense,
y
^
|
|||||
|||||
||z|| --- x
|||||
|||||


Here y is the long axis.
No Excuses
One change, btw:

The coefficients for the tires were incorrectly given above.

The actual coefficients are

A = abs(cos(theta))
B = -abs(sin(theta))

Otherwise, the straight-line force would be the full force, which would just be crayzee (rolling friction notwithstanding).

Yeah. Been a while since I did trigonometry in my head. Sorry about that.
No Excuses
heh after writing that long axis post I realized how stupid it was :)

in my app, XZ is the ground plane and Y is up :) but I understand what do you mean.

I took some time to check my workbooks from physics classes, and to my suprise, I found most of the equations you gave me. so i vector is positioned at front tires axis pointing up and j vector is positioned at back tires, same with A, B right?
OpenGL fanboy.
Quote:so i vector is positioned at front tires axis pointing up and j vector is positioned at back tires, same with A, B right?


No. The i vector, in my diagram, would be along the positive y axis. j would be along the positive x axis. A vector doesn't really have a "position", although if you're implementing rotational physics as well (and for drifting, you'll have to), the point of application is at the front tire contact points, and the force of friction is technically halved or quartered (I haven't got the time at the moment to solve the system, sorry).

I didn't really think about this when doing my diagram, but in "normal" notation, i would be along the x axis and j along the y. To do this all you have to do is rotate the frame of reference 90 deg CCW, so that the x axis is pointing "up" and the y axis points "left". For a lot of oval-track racing, that matches the typical application of this particular physics.
No Excuses
I have combined your code with http://www.purebasic.fr/english/viewtopic.php?p=213989&sid=1f955ee1090d652c1ceb54a3b94298d3 this one and now it works perfectly, even handbrake works :D
OpenGL fanboy.
Excellent :)
No Excuses

This topic is closed to new replies.

Advertisement