Help With 2D Car Physics / Drifting

Nibbie
Posts: 1
Joined: 2015.04
Post: #1
Hi guys. I'm looking for some pointers on how to add simple drifting to my top down 2D car object.

I am brand new to computer programming but have always fancied giving it a try so I thought the best way to

learn was by doing Smile

I'm not very good at maths and my logic is very suspect at the best of times lol

However; Using C++ and Allegro 5 I have managed to load a car sprite to screen which accepts user inputs via

the arrow keys to move it in all directions. I've even managed to apply a camera that follows the sprite,

although I'm struggling with creating a dead zone for that (that's for another thread though).

At the moment my car turns in a perfect circle with amazing downforce at all speeds! I need to add an element

of realism here and make the car skid/drift when turning too fast.

My acceleration is calculated thus:
Code:
acceleration += object.engineForce / object.carMass;
Engine force and car mass are arbitrary values. Maybe someone could offer more realistic values for these?

To turn my car I'm using a really crude method:
Code:
if(keys[LEFT])
    object.angle -= 0.07;
if(keys[RIGHT])
    object.angle += 0.07;


My vector is calculated as such:
Code:
object.x += cos(object.angle) * object.velocity;
object.y += sin(object.angle) * object.velocity;

My velocity:
Code:
object.velocity += acceleration;

Rolling resistance is just a simple:
Code:
object.velocity -= 0.1;

And finally, I rotate my sprite using:
Code:
object.camX = object.x - cameraX;
object.camY = object.y - cameraY;
al_draw_rotated_bitmap(object.image, 75, 25, object.camX, object.camY, object.angle, 0);

I'm hoping that these basic equations can easily be expanded to be able to add the drifting I'm looking for.

Any help will be greatly apprecited.

Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Bullet Physics Library / COLLADA physics viewer erwincoumans 14 18,262 Aug 12, 2006 12:59 AM
Last Post: Fenris