iDevGames Forums
Help With 2D Car Physics / Drifting - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Help With 2D Car Physics / Drifting (/thread-11682.html)

Help With 2D Car Physics / Drifting - nortski - Apr 20, 2015 01:46 PM

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:
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:
    object.angle -= 0.07;
    object.angle += 0.07;

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

My velocity:
object.velocity += acceleration;

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

And finally, I rotate my sprite using:
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.