Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How would I go about creating vehicle physics for a car that can loose traction? I want it to seem like the driver has a flat foot, so when you press the gas, they cars driving (rear) wheels loose traction, and makes it somewhat hard to control. I would also like to be able to do doughnuts and "drift" around corners.

I would also need to know how much "skid" is happening, so I can add a proportional amount of smoke and tire marks.

Assume a 2d, top-down style car game.

Thanks

share|improve this question
add comment

4 Answers

up vote 5 down vote accepted

This is a very simplified version but would be fine for most arcade type games. You need the following properties:

positionX, positionY - where the car is
velocityX, velocityY - speed on each axis
drag - how fast the car slows down
angle - the rotation of the car, in radians
angularVelocity - speed the car is spinning, in radians
angularDrag - how fast the car stops spinning
power - how fast car can accelerate
turnSpeed - how fast to turn

every frame:

positionX += velocityX
positionY += velocityY
velocityX *= drag
velocityY *= drag
angle += angularVelocity
angularVelocity *= angularDrag

to accelerate

velocityX += sin(angle) * power;
velocityY += cos(angle) * power;

to steer left

angularVelocity -= turnSpeed;

to steer right

angularVelocity += turnSpeed;

To get good drift, set drag and angularDrag to very close to 1, e.g. 0.9

share|improve this answer
    
So the controls would be power (throttle) and angular velocity (steering)? Or am I missing some transformation? –  drxzcl Jul 30 '10 at 15:51
    
no that's it - forgot to explain how to steer. Have updated with new turnSpeed variable. –  Iain Jul 30 '10 at 16:42
add comment

I was reading a paper today which simulates some vehicle dynamics during a collision and spin-out:

Jing Zhou; Jianbo Lu; Huei Peng, "Vehicle Dynamics in Response to the Maneuver of Precision Immobilization Technique", Proceedings of 2008 ASME Dynamic Systems and Control Conference

This contains a physics model which represents roll-over moment and loss of rear-tire traction during yaw caused by a deliberate collision force. It seems interesting to game programmers interested in vehicle dynamics during collisions.

share|improve this answer
add comment

I don't generally recommend Bourg's Physics for Game Programmers, but he talks about this a bit in Chapter 10 (around page 171), and might give you a starting point.

Unfortunately, the vehicle code in PhysX is still 'sample' and not well documented, so you can't easily figure out how that works. I believe I've seen code derived from their sample display the kind of behavior you're looking for in 3D, but it's a lower-level simulation than I think you want.

share|improve this answer
add comment

First things you need to understand are "slip ratio" and the "traction circle". Slip ratio is a good approximation for tire behavior, with a non-linear relationship between angle difference and lateral tire force. It also provides you with driver torque feedback information (for force feedback steering wheel).

The super simple version of both concepts are as follows: the more angle difference between rolling direction and movement direction, the more force there is perpendicular to the rolling direction (lateral force). It reaches peak at (typically) maybe 5° to 8° and falls off from there if tire angle is increased.

The traction circle is basically a limiter that clips off any force vector that goes outside it. It models the way that heavy acceleration/braking reduces steering ability, and vice versa. The size of the traction circle (max traction force vector) scales with the force pressing the tire onto the ground.

You'd need to model the lateral (steering) force separately from the driving/braking (rotational) torque and the opposing traction force from the ground.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.