Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

FlorianapoliS

Car - High Speed Cornering

This topic is 5822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been working on a car game (2D Top Down), I have straight line physics all good, but now I want to make my car turn I know how to make the car turn depending on the direction of the wheels using: R = WheelBase / Sin(SteerAngle) and then Omega = R / Velocity to get Angular Velocity but I''m wondering how to I get my car to slide etc depending on the force acting upon the car? I''ve looked at the tutorial: http://home.planet.nl/~monstrous/tutcar.html but I''m struggling somewhat to understand sections. Is there anyway I can get the forces relative to the car, such as breaking them down to a forward force, and a sideways force? As this would make it much easier to work with. I had a look at the source code of the little game in the epilogue of the tutorial, and I noticed this: velocity.x = cs * car->velocity_wc.y + sn * car->velocity_wc.x; velocity.y = -sn * car->velocity_wc.y + cs * car->velocity_wc.x; is that along the lines of what I need? And if anyone could give me a brief layout of what calculations to makeand in what order, to get realistc steering as the tutorial is a bit all over the place that would be a great help, thanks for your time

Share this post


Link to post
Share on other sites
Advertisement
I think there was a post about something like this earlier, try looking a month or so back. Anyways. You know about centripital acceleration, right? In order for the car to maintain motion along a curved path of radius r and moving at a velocity v, a force must be exerted inward equal to mass * velocity squared / r. The force that causes this is the friction of the wheels against the road. When you talk about slipping action, the force of friction is less than that needed to maintain the circular motion. At the point where this happens, the car is going to have some velocity vector v. The cal will also be accelerating inward with an acceleration of mu(kenetic)*g (assuming all the cars mass rests on the wheels). Furthermore, there will be an acceleration in the direction the drive wheels are pointing with a magnitude of up to mu(kenetic)*g, directly proportional to how fast the throttle is going. Hopefully this helps you out. You will need to do some integration here (non-constant accels), so that will also be a problem needing to be overcome.
Brendan

Share this post


Link to post
Share on other sites
Those two lines of equations look like rotation transforms from when I was learning 3d transform math...

Ok... here''s what *I* would do:

Give your car a position, velocity and acceleration, as well as amount of rotation. I wouldn''t bother with angular velocity or acceleration since it sounds like a fairly arcade-ish game.

All of the position based stuff would be 2D vectors (just a float x,y struct or class with some overloaded math operators to make things easy).

When you hit the gas, set the acceleration to be a vector in the direction that the car is pointing.

Each frame of the game, figure out how much time has passed since the last frame (timeGetTime or uclock functions are my favorites), you use this for a "delta-t" (change in time) for a couple simple equations:

velocity += acceleration * delta_t;
position += velocity * delta_t;

assuming you have the += and * operators overloaded properly (you get the idea), this updates your position and velocity.

Now, doing ONLY what I have said above, you get the effect of a ship in space using it''s thrusters... you have no friction of any kind, and no top speed.

You have choices... I usually multiply velocity by (0.99*t) (sorta-like friction) each frame. (insert some number between 0 and 1 until it feels right)

If you can apply just the right amount of acceleration and turning speed and friction, the car will drive pretty convincingly. You also need to figure out a way to have a top speed for your car... I''m not sure if the friction force ends up causing this or not, but it seems like it will.

I think you can figure out the rest.

Share this post


Link to post
Share on other sites
I''ve tried something very similar to what you have suggested before, but even after trying different values to multiply the car velocity by, you can still get the car performing 360 etc... and is fairly unrealistic?

Share this post


Link to post
Share on other sites
quote:
Original post by FlorianapoliS
Anyone else got any suggestions? As I''m really stuck here, and have been racking my brains out (well whats left anyway).



I just had an idea, that maybe when car has a velocity vector to direct where it is goin, ok. Then the turn comes and this velocity vector changes to new direction, ok. So what if u store the speed vector before car turns then when u move the car to new vector direction u also move it a litle bit to that old vector direction where the car was heading before the turn.
Was that understandable?

that should work like real physics if u now the right timing.. I dont.

Share this post


Link to post
Share on other sites
I''ve been thinking about this question for ages now and I''ve come up with something a bit fuzzy.

A particle is travelling in a circle with velocity v (m/s). It turns through an angle of (theta) degrees per second (rad/s).

In theta radians it will travel v metres.

A full circle is 2 * pi * r.

To turn through the full circle it must make 2 * pi / theta rotations. Therefore 2 * pi / theta * v = 2 * pi * r.

Which ofcourse is just r = v/theta.

Is this correct? At first I just said the radius can be calculated using s = r * theta where s is the arc lenghth. This seems to confirm that the angle you are turning through is the same as the angle of the centre of the circle.

Therefore F = m * v^2 / r and we get that the centripetal force F = m & v^2 / (v/theta) = m * v * theta.

Now knowing this we can give the tyres a frictional force constant. Call it T

Therefore the ''skid force'', S, is simply:
S = |F - T| acting in the direction of the radius vector or more simply sideways to the car. Now we can add the velocity vector and a sideways force vector.

Now this is the bit I''m stuck at, let me draw a picture...

V
^
|
|
C---->F

We need to modify the velocity vector based on this force at 90 degrees to it.

Help please :-)

Share this post


Link to post
Share on other sites
When looking at problems like this, all you need to do is consider newtons law F = ma. There are forces acting on the car, all of which come from the wheels. A driving force is pointed in the direction that the wheels are facing at a given time. Furthermore, when you turn a car, it is the friction (always pointed in the opposite direction of motion) that causes the car to keep turning. If you have ever driven on ice and started sliding, you will know exactly what I am talking about. The problem is that once you start turning too fast, the friction isn''t enough, that is we have exceeded the limit of static friction between the wheel and the road. At this point we are using kinetic friction which is going to be less, so the car will slide out of the curve. Now the problem I think you are having is that when the car experiences an acceleration below a critical value g*static coefficient of friction, static friction will take over once again. So we go from a transition of stable steering to sliding out of control, and while all this is happening the car is hopefully slowing down (keep track of that kinetic fiction), and eventually stop. You might not be transitioning back into the kinetic friction after some amount of time. Read my post above to see how the forces are acting and try implementing something like that.

Brendan

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!