Advertisement

Math for making a car "slide" ?

Started by March 15, 2000 04:12 AM
5 comments, last by BeeT 24 years, 6 months ago
Hi ! I was wondering if you guys know of any good site on the internet wich explains simple game math? Im making a simple car game. Go around a track and when you turn the car it should slide in the corners. Also this should be diffrent on diffrent surfaces. Any help would be great! //BeeT
This is physics, not math.

The steps you need to take to handle the cars goes like this:


  1. Update the cars position by adding its speed multiplied with the deltatime
  2. Apply friction to the cars speed. The friction is based on a number of things:

    • the cars weight
    • ground type (asphalt, gravel, grass etc)
    • the angle between the cars orientation and speed (unless the tyres are locked in break)
    • the speed, higher speed gives more friction

  3. Apply break forces. Since breaking only slows down the wheels rotationspeed, it only works if the car is oriented the same way its moving.
  4. Accelerate the car. The acceleration is of course affected by ground type.


I haven''t really studied car physics so I have most likely missed a couple of things here, but it should be enough to get a reasonable realistic behavior.

Advertisement
I would do it like this:

x_pos
y_pos
DIRECTION
CURRENT_SPEED_X
CURRENT_SPEED_Y
ACCELERATION_CONSTANT

If the user hits the left/right (or however you are doing steering) this would change the cars direction.
up/down (or however you are doing the gas pedal) are doing that, would ADD to the current speed the acceleratoin constant.

pseudo_code
{
right/left> turns cars pointing direction
up>
current_speed_x += cos(direction) * acceleration_constant
current_speed_y += sin(direction) * acceleration_constant
down>
current_speed_x -= cos(direction) * acceleration_constant
current_speed_y -= sin(direction) * acceleration_constant

x_pos += curent_speed_x
y_pos += curent_speed_y

(to do friction just decrease current_speed_x and current_speed_y to like 90% of their current value. I just made up 90%, you''d hafta figure that up yourself. you''d also have to make up acceleration_constant depending on your game)

draw car facing DIRECTION at (x_pos, y_pos)
}

--------
hope this helps. =)
http://fakemind.com
This stuff will should help.

http://members.home.net/rck/phor/index.html
Play free Java games at: www.infinitepixels.com
Yep, this is physics. The sliding frictional force is directly proportional to the normal force (which is approximately the weight). So we have

F = u*M*g where F is the force, M is the mass, g is 9.8m/s^2 and u is the frictional constant. What you are looking for is a change in momentum, do we have dP/dt=uMg, or change in momentum=u*M*g*dt. dt is the time interval, and u*g is a constant you want to play around w/ a bit.

Hope this helped some.

Mike
"Unintentional death of one civilian by the US is a tragedy; intentional slaughter of a million by Saddam - a statistic." - Unknown
Well, it seems there is a lot of confusion in this thread..

I'm going to try to explain how to implement basic game physics and then how to use them in your racing game project

Basically, if you want to add some basic physics you have to use the Newton's equation:

Forces=mass*acceleration

The tricky part is to find the forces acting on your object. If you know them and can express them with vectors, you just have to divide them by the mass and you get the accelaration of the object, that is, how fast and in wich direction the velocity does change. To get the new position of your object, just add the velocity to the previous postition.

Well, maybe it sounds too abstract. Here is how to implement it step by step:

for every frame

a) Calculate the acceleration of your object:

1. sum up the forces acting on your object

2. multiply this sum with the mass of the object

b) Update the position of your object

1. update the velocity (add the acceleration to the previous velocity)

2. update the position (add the velocity to the previous postion).

---

Well so far so good, in my next post, I'll show you how to use that in your racing car project.


Edited by - SuperBlaireau on 3/15/00 2:50:28 PM
Advertisement
other people have had good ways to do this. I just wanted to say that the way I did it was the very simplest way to produce natural looking car physics to make the car skid and slide around turns and such.

You would only need momentum (mass and velocity) for collisions. IMO

http://fakemind.com

This topic is closed to new replies.

Advertisement