## Simulating A Car

Sage
Posts: 1,066
Joined: 2004.07
Post: #1
I'm working on a car game at the current time (or at least creating a system of car physics) and am having trouble figuring out how to simulate something like a car. There needs to be an acceleration factor along with a friction. Then there's the top speed and current speed. There's also (because I'm working with a top-down view like original GTA) a vector set up with the direction in which I'm moving. Can anyone help me? I can't seem to find a system that works and it's frustrating me.
Moderator
Posts: 916
Joined: 2002.10
Post: #2
SimReality/Nick Wrote:I'm working on a car game at the current time (or at least creating a system of car physics) and am having trouble figuring out how to simulate something like a car. There needs to be an acceleration factor along with a friction. Then there's the top speed and current speed. There's also (because I'm working with a top-down view like original GTA) a vector set up with the direction in which I'm moving. Can anyone help me? I can't seem to find a system that works and it's frustrating me.
well, whatever you do, don't go for exact perfect simulation... Some unrealism leads to a lot of better gameplay..
Sage
Posts: 1,066
Joined: 2004.07
Post: #3
Yeah I love the physics of the new GTA game. The blur effect and the high speeds along with the insane crashes that send cars barreling down the road. I love those physics. Too real of physics are game killers (unless you're going for a sim like Gran Turismo 4).
Member
Posts: 156
Joined: 2002.10
Post: #4
One way to do this is by doing a reasonably realistic physics simulation:

Give the car a velocity vector. When accelerating you just increase the velocity vector, and to turn you alter the angle of the vector. As far as limiting top speed goes you can either do it by applying a frictional force. This force should be proportional to the velocity vector but in the opposite direction, thus it will slow the car down. If your acceleration is fixed, then at some point your speed will max out when the frictions becomes equal to the velocity. The alternative way is just to put a maximum speed on, and rescale your velocity vector so that the speed (the magnitude of the vector) never exceeds your max speed. Then you will have to manually apply friction, e.g. by decreasing the velocity vector every timestep when you are not holding the accelerator (gas pedal) down.

To do some really cool effects, you can model the car as a rigid system with mass concetrated at two ends (think like a dumbell), and apply your friction and steering to each mass seperately, allowing you to do cool things like sliding the back end out, front & rear steering etc.

Have fun

- Iain
isgoed
Unregistered

Post: #5
You can go for rigid body euler integration. I used it for my game adrenalin racing. You need a quite good understanding of newtonian movement. I still don't master it completely. Especially collisions between hard objects is difficult. A great tutorial(s) is available on http://home.planet.nl/~monstrous/mons.html

What I recommend at this moment is using a verlet integration physics engine. All new games use it nowadays and remarkable enough you don't need to have a lot of insight in newtonian physics. On this forum someone made a very realistic game (in progress), which I believed was based on verlet. It featured a marine which could step into a jeep and drive a circle in a desert terain. All physics engines based on verlet integration often feature a carphysics example. (I know PC engine "Meqon", does a real good job: http://meqon.com/products/game/features.php )
Member
Posts: 509
Joined: 2002.05
Post: #6
isgoed Wrote:What I recommend at this moment is using a verlet integration physics engine. All new games use it nowadays and remarkable enough you don't need to have a lot of insight in newtonian physics. On this forum someone made a very realistic game (in progress), which I believed was based on verlet. It featured a marine which could step into a jeep and drive a circle in a desert terain. All physics engines based on verlet integration often feature a carphysics example. (I know PC engine "Meqon", does a real good job: http://meqon.com/products/game/features.php )

Thats what I recomend, its working good for my motorcycle simulation. Its increadibly easy to impliment too. There is a good article somewhere on it, I can't remember the URL right now.
Sage
Posts: 1,199
Joined: 2004.10
Post: #7
If you're not interested in writing your own physics, I'd recommend looking into ODE. I'm using it for robotics and simultaneously for a driving type game. It's a rigid body system, so it has its drawbacks but it also happens to allow for some sophisticated stuff.

In my game, my rover has a fully articulated suspension and four wheel steering, plus a "gun turret" thing. The rover's suspension works as you'd expect and the overall performance is quite convincing. Plus, it's a lot of fun to drive.

Best thing is, since you don't have to roll your own physics you can spend more time on the fun stuff, like gameplay, AI and graphics. As far as I'm concerned, physics is like OpenGL -- I'll leave it to the experts. I'm not going to write my own 3d rasterizer ( actually, I have before ), and I'm not going to write my own physics ( again, I have before ). It's not worth your time unless you really want to do it yourself.
isgoed
Unregistered

Post: #8
Jake Wrote:Thats what I recomend, its working good for my motorcycle simulation. Its increadibly easy to impliment too. There is a good article somewhere on it, I can't remember the URL right now.

Yeah the article is http://www.ioi.dk/Homepages/thomasj/publ...dc2001.htm

I made an example physics engine based on this ( http://www.revaro.net/developer ). I don't know if there are any mac verlet physics engines available. If you want to write your own engine, you can look at my file PhysicsEngine.cpp. That is basically all you need. But remember that collision detection is a whole other art that you need to write yourself and it is usually very difficult to write fast code and without bugs (correctly detecting collisions).
Sage
Posts: 1,066
Joined: 2004.07
Post: #9
I'm not sure what I'll do for collisions but I think I'm going to at least attempt to make my own car physics.
Sage
Posts: 1,066
Joined: 2004.07
Post: #10
I've found a nice site for creating the physics of driving for a car. Unfortunately 1) I have never taken a physics course yet so I'm lost on most of it and 2) it's a bit much for a top down game that is supposed to feel like playing GTA. Can anyone help me (excuse the term) dumb it down a bit and explain it to me? It's quite a daunting task I'm asking but if anyone has time to look at it and help me out I would appreciate. Please IM me on AIM at nickgravelyn if you are willing to help.
Sage
Posts: 1,487
Joined: 2002.09
Post: #11
I don't think it can be made all that much simpler. It's fairly straight forward as is. You don't really need to understand the physics behind the formulas per se, but if you don't get the math, I don't see how it can be simplified much.

If you don't get it, try to find a library that will do it for you. ODE is great for 3D stuff, but not so much so for 2D.

I'm currently working on the new version of SPK which will be intended for 2D games. Initially it won't be well suited for rigid body physics for cars, but considering that I initially started it for a top down car racer, you can bet it's a priority.
Sage
Posts: 1,066
Joined: 2004.07
Post: #12
I'm just not sure how it all fits together. I tried writing all of the equations near each other for a visual representation and possibly match them up. I don't want to use a library. I would like to make my own. And as for dumbing it down, I'm sure there must be a couple variables or equations I can take it out. I don't need Grand Turismo realism here, just a simple driving engine.
Member
Posts: 40
Joined: 2002.04
Post: #13
On the monstrous software website there is a link to a Java playable version of the tutorial. Have a play of that, it feels very GTA-ish. If you can understand Java, just rip out the physics part and throw it in your game. It's not really neccessary to understand it all, just fiddle round with the constants and you can get it working nicely.
Sage
Posts: 1,066
Joined: 2004.07
Post: #14
The java link is an Unfound Website Error. Oh well.
Member
Posts: 40
Joined: 2002.04
Post: #15
I think I kept the Java example lying around on my laptop (which incidently is not with me at the moment), but I should be able to post it tomorrow.