# Thread: Howto implement simple 2d car drift

1. ## Howto implement simple 2d car drift

Im working on a 2d topdown race game and i need some help. The car needs to drift and I want to do it without any heavy math because the game has to run on mobile phones.

2. By drift do you mean that the car should automatically move slowly to the right or left or what have you? If you do, then...

I assume you're updating the position of the car in a loop.
Have a tracker variable that is incremented by one every time the loop is completed.
Once the tracker variable reaches, say 100 (you probably will need to change this), increase another constant by one.
Use this constant to calculate the x-position.
Reset the tracker and the constant when the commands are given to go left or right

Play about with something like that, i'd suggest.

If you need any more help, or can be more specific, i'd be glad to help,

Cheers,

Åge Kruger

3. Oh. Well, that does look quite difficult. I'm not entirely sure how to do that. I suppose if your car's front and rear were given by coordinates instead of just the center of the car or something, then you'd be able to change the orientation of the car. I'm nut sure if this iis "hard maths", but i'd do that by calculating an arc for the front and rear to follow. Then i'd just increase the coordinates as normal in the correct direction, and have another arc to get it out of the drift.

This drifting stuff seems a bit OTT for a 2D mobile phone game, but you can probably be sure that it'll make your game unique!

Åge Kruger

4. Having two separate vectors for speed and acceleration should do the trick. The user input affects the acceleration, and the acceleration later affects the speed, so the when the user turns left the car will keep on going straight for a while. Once you have that implmemented it's just a balancing act to get it to behave the way you want.

shmoove

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•