2d car physics question
Posted 02 April 2010 - 07:43 PM
The first thing I done was to create a rigid body structure for the car body that has some properties: mass, inertia etc. The main function of this structure is to be able to apply forces at specific points and for it to rotate and translate itself accordingly. All this works fine.
The problem I'm having is with the wheels... I know the velocity of the wheels and the direction they are heading, The angle between these two vectors is commonly refered to as 'slip angle' I think. Currently I split the velocity into two components - side velocity and forward velocity (side velocity is how many m/s the tyre is moving on its side and same with forward) and then I apply a force in the opposite direction of the side velocity to the car, this force is proportional to the velocity. This method seems to work, I just set a coefficient that gets multiplied with the inverse side velocity and use this vector as a force that I apply to the car. Can someone tell me velocity is linearly proportional to force in this case (seems to work).
I've tryed doing it the proper way by storing the previous frames side velocity and then differentiating over a a certain time (1/50th second (50fps)) to give me the acceleration which I then plug into (F=ma).(I say 'proper way' but I really dont know if it is) If the tyre pushes the ground and the ground pushes back with an equal amount of force then why doesn;t this work. (do I also need to take inertia into account).
p.s. I dont take weight transfer into account, in the calculations mass is just car.mass / 4.0
Posted 02 April 2010 - 08:00 PM
So basically you're already doing the right thing except for the friction force being proportional to the velocity - friction is substantially independent of velocity. (If you were talking about fluid drag, such as from a boat motoring through the ocean, then the drag would be proportional to velocity, at slow speeds - and velocity squared at high speeds.)
Posted 02 April 2010 - 08:23 PM
So the magnitude of the friction force stays the same (assuming no weight transfer) its just the direction of the force changes. And this also means I don't need to calculate the net force from the current and previous velocity... I just apply friction force and its gets integrated in on the next update. thanks, I'll try implemnting it and see what happens.
Posted 03 April 2010 - 07:35 PM
basically the car body has an angular velocity as soon as I turn the wheels when driving - this velocity will go up (or down) clockwise/anti-clockwise.
The problem is that I get the velocity of the tyre using this angular velocity and the relative offset of the tyre from the cars center of mass. The velocity of the tyre is then used to determine the direction of friction, therefore I apply the friction force in the opposite direction of velocity, which , in the next frame, causes the velocity of that tyre to be in the other direction. This is an infinite loop where the velocity of the tyre switches between negative and positive every 2 frames, the forces of friction balance each other out but not in the same frame. therefore the image jitters about quite noticably. Also when I turn the wheels when the car is stationary it starts to slowly rotate about its center and then back again. I think this is because a force is being applied one frame, the wheels turn (between frames) and then a new set of friction forces applied in the next frame causing an imbalanced force.
Is there any way I can solve this?
Posted 03 April 2010 - 08:10 PM
Posted 03 April 2010 - 08:49 PM
F = ma
a = (vf - vi)/t
a = (0 - vi)/t
F = -vi/t * (carMass/4);
I then just check if friction force is greater than this, ifso use this instead.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users