# 2D Car Drifting

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

## Recommended Posts

Hey all,

I've got pretty much the most basic overhead 2d car physics going on:

 velocity.x = Math.cos(angle) * speed; velocity.y = Math.sin(angle) * speed; position.x += velocity.x * deltaTime; position.y += velocity.y * deltaTime; 

Pretty basic -- change speed to go faster / slower / reverse and increase / decrease angle to turn.

Everything works, but it feels pretty boring to drive.

How would I go about drifting? Nothing too realistic, just something fun and arcadey where the more you turn, the more you slide unless you counter-turn.

Thanks!

##### Share on other sites
instead of allowing your car to move in the direction it's facing, you can take in account that it still has momentum going in the direction it used to be facing? Ie just because you turn the wheel doesn't mean you're going to go in that direction.

Your car has an angle that it is facing, and an angle that it is moving. So gradually alter the cars moving angle to match the facing angle. Hopefully that makes sense... I'm currently in the middle of a dumb aurgument and yes as I write this they are getting even angrier and my smile is getting bigger... so I'm having a hard time concentrating.

##### Share on other sites

instead of allowing your car to move in the direction it's facing, you can take in account that it still has momentum going in the direction it used to be facing? Ie just because you turn the wheel doesn't mean you're going to go in that direction.

That sounds like spaceship physics rather than car physics. Cars DO go in the direction they face unless you turn so fast the momentum is enough to lose friction. Once that happens the above method should be fine enough. But mostly it boils down to switching between the two types of friction.

##### Share on other sites

That sounds like spaceship physics rather than car physics. Cars DO go in the direction they face unless you turn so fast the momentum is enough to lose friction. Once that happens the above method should be fine enough. But mostly it boils down to switching between the two types of friction.
"Spaceship physics" is still what's required to make it act like a real car. Cars go in the direction they're facing because there is friction constantly pushing back against 'slide' movements. So if you create a slippery 'spaceship' and then add tire friction, you've got a car.
e.g. quick idea of basic physics, this time starting with force, not velocitycar.force = (0,0) for each wheel slideFrictionAmount = 1.0 - abs( dot( wheel.forward, car.velocity ) );//1 when perpendicular, 0 when parallel car.force += -velocity * tweakableNumber;//what percentage of sideways movement is converted into an opposing force if( wheel.powered ) car.force += wheel.forward * tweakableNumber2;//engine power car.acceleration = car.force / car.mass car.velocity += car.acceleration * deltaTime car.position += car.velocity * deltaTimeThat said, the friction behaviour of rubber tires is quite complex, and the above model will require a lot of tweaking to get something 'fun'... Just cheating by switching between two 'modes', like Trienco suggested, may be a lot easier to achieve a result with More complex car games simply use magic.

1. 1
2. 2
frob
15
3. 3
4. 4
Rutin
12
5. 5

• 13
• 12
• 58
• 14
• 15
• ### Forum Statistics

• Total Topics
632121
• Total Posts
3004231

×