Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Math for making a car "slide" ?

This topic is 6641 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
I would do it like this:


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.

right/left> turns cars pointing direction
current_speed_x += cos(direction) * acceleration_constant
current_speed_y += sin(direction) * acceleration_constant
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. =)

Share this post

Link to post
Share on other sites
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.


Share this post

Link to post
Share on other sites
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:


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

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!