Simple Car Physics? (sorry)

Recommended Posts

UselessRob    122
Howdy I know this gets asked a lot, but I'm still struggling to find an answer, so I'll take a risk and ask my question in hopes that you guys will understand. :) I'm trying to do some simple car physics. I have a nice 2D version going (nice enough for what I need anyway) that I made from the old (and now extinct?) monstrous tutorial. What I'd like to do tho, is make it 3D. By that I mean make the car notice ramps or changes in the road angle or whatever, instead of always being flat. First question is: has anyone made a 3D example out of the monstrous tut? If so, could someone give me some hints on how it's done? I'm not really looking for realism, just something that works in 3D at this stage. Second question is: Rather than using something I've dodgily slapped together, is there a way to do some simple car stuff using one of the engines that are around such as ODE, and if so is there a tut somewhere explaining how to do that? I need to be able to port between Windows and Mac, which is why I was trying to do the basic physics stuff myself, but I just don't have the brain power. The porting means I'm not sure which engine to use, if it's even necessary to use one. Again, I know it's a common question, but I just can't find the answer. So any help would be very much appreciated! Thanks! Rob.

Share on other sites
Bob Janova    769
A simple idea: First find the plane on which your car lies. Find out where each wheel would like to be (from your terrain) and pick the plane that leaves one point below it. Then apply a gravitational 'force' scaled by dot_product(world up vector, cross_product(car right vector, plane normal)). That won't allow the car to slip sideways down a hill; if you want that just apply the force in the plane of the, uh, plane of the car.

Share on other sites
UselessRob    122
Thanks for the reply. I thought about this method myself, but I came to a problem and I can't remember what it was.

So I should work out for each wheel position which polygon for the "road" it's actually inside, and then work out from that poly's plane equation what the height of the wheel should be, yes? I think the problem I thought would happen is that the wheel would move outward from the car's chassis. Does that make any sense? Like you need to know the angle of the car before you can work out the angle of the car?

Or am I way off and totally stupid?

Share on other sites
Motorherp    613
The way I do it is I have 4 vectors in the cars local space which are offsets to the top of the 4 suspension struts. For each of the suspension starting points I collide with the terrain a ray whose origin is the above point and whose direction is the cars negative y axis. The distance between the suspension starting point and the terrain intersection point minus the wheel radius gives me the the suspension length. The wheel position is then at the suspension starting point plus the length times the negative y axis. This way the wheels will never move side to side outside of the chassis. Obviously if the suspension length is above the suspensions maximum extension then we cap it at the max and that wheel is considererd non-colliding. If the wheel does collide then calculate its lateral and longitudinal forces in the plane of the polygon the suspension ray intersected.

Quote:
 Does that make any sense? Like you need to know the angle of the car before you can work out the angle of the car?

It can get confusing since these kind of problems feed back into themselves. Depending on which way you do it one calculation will always be one step behind another but it all works out in the long run. For example we take the cars y axis to determine the suspension ray direction which determines the wheels' contact points. These then leed to suspension torques being applied to the car which changes its y axis and results in a different suspension ray direction next step.

Share on other sites
UselessRob    122
Ok, I think this is starting to make some sense. Thanks a lot for the theory, let's see if I've got it right:

Have wheel positions in "car space"
Project rays from each wheel pos to the "road" planes that each wheel is inside of, along the down axis as per the car's rotation.
Check distance. If it's too far, the wheel is at max suspension. If it's less than that, the wheel is at ground level.
So then, you work out from the wheel positions the plane of the car?
From the plane of the car, you know which direction it should drive in in 3D space?
Does this mean there would be a separate car angle for the chassis? Since the different suspension levels would mean the body was independant of the wheels?

I'm getting confused again. I'm guess then the problem becomes movement. The car can't simply move at it's new angle, the drive would need to depend on which wheels are colliding with the ground? And if the wheels are off the ground, is gravity applied evenly, or weighted depending on it's position in the car? The front may be heavier for example?

It seems even trying to do simple car physics in 3D isn't all that simple!

Share on other sites
Bob Janova    769
Quote:
 Original post by UselessRobLike you need to know the angle of the car before you can work out the angle of the car?

Yes, this is true. Remember, we're in gaming mode not correct mode here, so as a hack you can move the wheels in the vertical axis first, then bring them in so the car is the right length, then adjust the Z position for their new XY, keep iterating till it's good enough (probably only 2 or 3 times anyway).