Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GTA2 like Car Physics, but extremely simplified

Okay so this problem has been bothering me for the longest time. Can anyone show me or point me to an algorithm that can control a car like that of GTA2? After 3 days of research all I could come up with was all of these algorithms for using pivot and joints on the wheels and separate wheels and such. Is that the only way to achieve simple car movement like that of GTA2?

I want to be able to use the algorithm on a rectangle without wheels but still be able to have the car drift. Is that possible? By the way, I am usign Box2D for the 2D game.

I know this is more suitable for gamedev but for some reason I can't post questions .

like image 270
Free Lancer Avatar asked Mar 01 '12 22:03

Free Lancer


2 Answers

A simple answer that can turn into something quite big so I will try to explain by presenting different points in an increasing order of sophistication. I will be assuming a basic knowledge of physics.

  1. Assume a fixed turning radius (not too bad if you are using a keyboard, quite annoying if you have an analog controller). Nothing like trying out different positions to find out what radius feels good.

  2. Assume that you have wheels that are initially facing forward and as you press the turn key they progressively turn to the maximum possible. This basically means decreasing the radius from infinity to your smallest possible radius (you can figure out the relationship between the angle of the wheels and the radius easily). If you have an analog controller then the radius should be controlled by the continuous values of the analog input.

  3. Let the forces enter! When you are turning in a car, you only turn due to a centripetal acceleration. That centripetal acceleration is caused by a force which is actually the friction of the car with the road. You can consider the friction a constant and the mass of your vehicle constant without major problems then you have a relatioship between the velocity of the car and the critical radius (the minimum radius you can turn given the velocity). The centripetal acceleration is a=v^2/r = Friction/mass so the critical radius r = v^2*mass/Friction. You can consider that no matter how much you turn you vehicle will drift and, at maximum, describe this curve. This should give you a nice simulation but still not the "losing control" feeling. For this see the next point! circular motion

  4. The theory is exactly the same as in the point before but the main thing is that Friction in reality is not constant. In fact, the static friction will always be higher that the kinetic friction. In practice, you should have a static friction and a (smaller) kinetic friction. You calculate r according to the static friction and when your velocity is too big to achieve that r (this is when you would drift) you start calculating the new r using the kinetic friction. This will give you the losing control feeling but the vehicle will still not spin. Friction

  5. In order to see the spin, you would have to consider the forces applied in every wheel (it is the fact that the different wheels are under different forces that makes the car spin) and consider some more advanced physics such as which wheels are the driving wheels and also consider the kinetic friction not a constant. However I believe this is out of your scope.

  6. Alternatively you can do something that GTA2 seemed to do. The moment you know you are going to drift or are drifting too much (you set a threshold here) just programmatically make the vehicle lose control and spin.

Hope this helps, if you have any specific doubt just ask.

like image 165
PhyBandit Avatar answered Sep 23 '22 22:09

PhyBandit


I found the http://www.banditracer.eu/carexample/ demonstrated a simple example for using Box2D to show car movement. The http://www.banditracer.eu/ has an open source game that you can observe to see if it has the drifting movement your looking for. You can check out the code and see how they handled the drifting movement and do the same for your project.

like image 31
GatorQue Avatar answered Sep 24 '22 22:09

GatorQue