# The simplest method of applying surface friction?

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

## Recommended Posts

Hello,

I'm working on my first game at the moment, an arcade style racing game, running on my proprietary 3D engine in AS3.

For performance reasons I'm also doing all physics and collision detection from scratch.

I have a basic car model working, basically a 3D rectangle comprised of 4 wheels and some constraints that can drive around and collide with the environment.

Albiet in basic and somewhat glitchy fashion, it works, but now I need to implement surface friction, so that for example if the car is perpendicular to the road on a hill, it won't slide down sideways.

Something of note is that I'm purposefully NOT following realistic car physics. I'm basically making the handling up, because I want it to be arcadey. The inspiration for this game is more Ridge Racer/Outrun 2 than Forza.

So without developing a fairly complex handling/physics system that references real racing physics, what is the best way to implement surface friction?

How do you think a game like Ridge Racer does it, with it's very basic, stylised handling?

Cheers,
RumbleSushi

##### Share on other sites
I'm no expert, but would the easiest way to implement friction would be to fake it?

##### Share on other sites
The simplest answer I can think of:

1. Compute net force on car, with constraints.
2. Project off lateral component.
3. Update velocity.
4. Multiply velocity by, say, 0.8.

This will give you a car that will never slide sideways, and whose velocity will slowly decay.

##### Share on other sites
smr, absolutely the best way would be to fake it, but I guess I'm just looking for the best way to fake it ;)

Emergent, thanks for your suggestion. I've been thinking perhaps the best way to fake it would be to just generate a sideways force on each wheel, then remove this force to initiate a drift etc. (Right now the car almost behaves as if it's on ice).

This should be relatively easy.

The tricky part is transferring the gravity into angled velocity according to car/wheel rotation.

Right now if the car is on a hill, gravity makes it slide down the hill, but without taking into account the wheel angles. It's basically a sliding plane collision response. So if the car is at a right angle to the road direction, it still slides down, but of course it shouldn't. The surface friction of the wheels should stop it.

I've tried rotating the velocity generated from the slide plane collision response according to the wheel rotation, but for some reason I can't get it working.

This image should illustrate how the surface friction should behave.

http://rumblesushi.com/stuff/gravity.jpg

##### Share on other sites
Quote:
 Original post by rumblesushiRight now if the car is on a hill, gravity makes it slide down the hill, but without taking into account the wheel angles.

That's what the "project off lateral component" part of my reply was about. I.e., if the car's left vector is 'n,' and the net force you calculate in step 1 is 'f' then the projected force is

f_proj = f - <f,n>/<n,n> n .

This doesn't take into account having multiple wheels, or the current steering angle; it's a very simple "quarter rolling"-type model.

I can describe fancier stuff too, but it seemed you wanted something simple, and simple this is. :-)

(I should add that you'll need to add a centrifical term when you turn.)

##### Share on other sites
Cheers. I'll try to get this working tonight.

How I'm handling the car now (RWD car model) is applying most of the force to the rear wheels, and a small amount to the front wheels, and of course rotating the velocity of the front wheels according to the car orientation and steering angle. Well, rotating the rear wheel velocity according to the orientation of the car too.

It's actually soft body mechanics basically, the car is comprised of 6 springs. Then the model is positioned by averaging the points and rotated according to the angles of the front/rear particles etc.

I update the velocity, process collisions with the environment, then update the constraints.

By "f_proj = f - <f,n>/<n,n> n" do you mean it's simply force - (F/lateral_vector) normalized? I'm not familiar with the pseudo code used.

How should this force be integrated exactly? Do you know of any source code with a basic "quarter rolling" source code?

Should it be integrated before sending the object to the collision routine, or as part of the collision response?

Cheers,
RumbleSushi

##### Share on other sites
Quote:
 Original post by rumblesushiI'm not familiar with the pseudo code used.

My bad; the angle brackets denote inner products (dot products).

Quote:
 Original post by rumblesushiHow should this force be integrated exactly? Do you know of any source code with a basic "quarter rolling" source code?

It's not too crucial how. Verlet, symplectic Euler, even plain old Euler... I might be able to come up with some code later...

Quote:
 Original post by rumblesushiShould it be integrated before sending the object to the collision routine, or as part of the collision response?

Not totally sure how your code works, but my guess is "after collision response."

##### Share on other sites
Thanks for the help Emergent.

It seems basic, so I'm annoyed I haven't been able to get it working. It's mainly because I have no experience of vehicle physics and no reference, literally just making it up as I go along.

In regards to pseudo code, it's not really used at all in the Flash development community so I'm often confused by some of it on this site ;)

What about the "n" after the dot products? What does that mean?

Some example code would be great if you would be so kind.

The basic physics pipeline per wheel is like this.

Apply force from wheels to velocity vector, integrate velocity to a destination position, send to collision class, return new position after slide plane collision response.

Then satisfy constraints.

##### Share on other sites
I use something like this:

$\mathbf{F}_{\perp} = \mathbf{n}\,(\mathbf{n}\bullet \mathbf{F})$

$\mathbf{v}_{\perp} = \mathbf{n}\,(\mathbf{n}\bullet \mathbf{v})$

$F_{fr} = \mu \, |\mathbf{F}_{\perp}|$

$\mathbf{I} = -\mathbf{v}_{\perp}\,\frac{m}{dt}$

$\mbox{if:}\;|\mathbf{I}| < F_{fr}$
$\mbox{.}\;\mathbf{F} = \mathbf{F} + \mathbf{I}$
$\mbox{else:}$
$\mbox{.}\;\mathbf{F} = \mathbf{F} + F_{fr}\,\frac{\mathbf{I}}{|\mathbf{I}|}$

So first get the component of force (including gravity) and velocity in direction of surface normal. Then calculate the kinetic friction magnitude. Then calculate an impulse that, when applied, will stop the car dead. Finally, if the strength of friction is too great, stop the vehicle dead using the impulse (approximating static friction). Otherwise apply friction force magnitude in direction of impulse (i.e. opposite direction of velocity).

That's linear friction. Angular friction is such a pain. But one step at a time, eh.

[Edited by - dangerdaveCS on December 3, 2010 6:24:14 PM]

##### Share on other sites
When your car is on a slope and you calculate the force vector (due to gravity causing the car to slide), you can project this vector onto the direction the wheels are facing, and also onto the vector perpendicular to the direction the wheels are facing. Then you apply separate friction modifiers to each vector. How you handle this is up to you, but normally you'd apply a friction term to the perpendicular vector which is large anough so the vehicle will resist sliding sideways on all but the steepest inclines, while it only takes a slight incline in the direction of the wheels to produce forward motion.
In a simple simulation the wheel axes don't turn during steering, but your program appears to be more complicated, so you handle each wheel separately, with the axis of the front wheels possibly being different to the back. On occasion you'll have situations where some of the wheels are on an incline while the others are flat. This introduces angular forces and center of mass, which you might want to fudge heavily unless you're familiar with that stuff.

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 35
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001808
×