• Create Account

## How would i implement friction?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

9 replies to this topic

### #1Waterlimon  Members

4373
Like
0Likes
Like

Posted 28 June 2013 - 01:07 PM

Im trying to add friction to my physics engine.

I know:

-The collision point and normal

-Properties of both bodies:

*Center of mass

*mass, inertia

*angular and linear velocity

*angular and linear forces

So, how would i go about implementing friction?

Currently i am able to apply a force to a point on a body (which translates to linear force and torque)

I am able to do friction for surface on surface (its a top down 2d game) where i assume the other surface to have infinite mass. However this directly modifies the velocity and im not sure how to translate that to friction from collisions.

The internet didnt seem very helpful on this one, anyone care to explain how to make it all work? Preferably in a way that works smoothly and wont estimate the forces wrong and cause everything to explode.

I tried to use my getDeltaVelocityCuzOfFriction(VelocityDifference, frictionCoeff, normalForce) method but since i dont have a method of setting force directly at a point on the body, and i dont know how to get the normal force, i couldnt get it to work. There might be other problems with my collision response that cause it to not work but i cant be sure until i know the friction itself should work.

Thanks.

o3o

### #2lithos  Members

414
Like
0Likes
Like

Posted 28 June 2013 - 02:13 PM

Every game tick I'd bring the velocity closer to zero.   Then have different reduction values for not touching the ground and touching it.

I'd probably ignore everything else like inertia, would probably even ignore how friction changes with speed(it doesn't but you're covering more distance).    To get things like terminal velocity if I needed it I would probably just "word of god" say you won't go faster than X speed.

EDIT:  A Lot of programmers even cheat a lot worse and just use look up tables for where a character should be in a jump in some cases.

______

It actually makes a lot sense why the Internet isn't being helpful to you.   Physics equations have all those exponents to keep track of totals/positions.   However you the programmer are already keeping track of the those totals by always knowing the exact position of your character at all times(well most times, and depending).

So if you want the 100% right and correct answer you should go looking for the derivatives of the physics equations you're looking at.

Edited by lithos, 28 June 2013 - 02:15 PM.

### #3Waterlimon  Members

4373
Like
0Likes
Like

Posted 28 June 2013 - 03:11 PM

I cant simplify it much since this isnt a platformer - there are no static parts.

I will make a "set velocity at point x" method and work with velocity instead of forces because that seemed to work for the simpler case.

I still need to find out how to find force of contact (ignoring gravity) and how to make it so that if a big and small object have friction between them, the big one wont move as much as the small one... hm.

o3o

### #4Khatharr  Members

7757
Like
0Likes
Like

Posted 28 June 2013 - 05:15 PM

F = ma

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

### #5DT....  Members

487
Like
0Likes
Like

Posted 28 June 2013 - 11:16 PM

http://www.gamedev.net/topic/465248-calculating-impulse-due-to-rigid-body-collision-with-friction/

### #6Norman Barrows  Members

6339
Like
0Likes
Like

Posted 29 June 2013 - 02:10 AM

I still need to find out how to find force of contact (ignoring gravity) and how to make it so that if a big and small object have friction between them, the big one wont move as much as the small one... hm.

that's impulse and momentum and conservation of momentum, not friction. 1st year mechanics. any decent college physics book will have the info.

as i recall, m1*v1+m2*v2 (inital - before collision) = m1*v1+m2*v2 (final - after collision).   or something like that, better look it up.  <g>.

friction is a totally different set of physics formulas.

with friction, the variables are mass, velocity (? been a long time), and Ks or Kd, the coefficient of static or dynamic friction, depending on whether you're sliding/skidding (dynamic) or not (static). Ks and Kd are constants that are empirically derived for two given surfaces (such as tire rubber and asphalt, ice on ice [which is about the lowest], etc).  the exact values of Ks and Kd are different for any 2 given surfaces.  but they all follow the general rule that Ks is higher than Kd (or is it always lower? <g> another one you'dd better look up). Ks and Kd essentially define the points at which you lose and regain traction, based on the speed, vehicle weight, and the type of friction surfaces.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

### #7Waterlimon  Members

4373
Like
0Likes
Like

Posted 30 June 2013 - 12:52 PM

I got dynamic friction working now (seems to)

But how to implement clamping so it won't jitter ?

It seems like a rather complicated problem. I can see it being possible with 2 bodies and some lengthy calculations with inertia and all, but for more bodies i think i need one of those "solver" things physics engines are full of. Any advice?

o3o

### #8Khatharr  Members

7757
Like
0Likes
Like

Posted 30 June 2013 - 02:03 PM

as i recall, m1*v1+m2*v2 (inital - before collision) = m1*v1+m2*v2 (final - after collision).   or something like that, better look it up.  <g>.

More or less correct. This is the conservation of momentum. The force (which is what you're calculating there) is equivalent, and gets split evenly between the colliding bodies. Calling it before and after, it should be specified that the body with larger mass will undergo the smaller acceleration.

This is essential Newtonian physics.

F = ma (force equals mass times acceleration)

Combined with the Third Law (opposite and equal reaction), you locate the point of impact, multiply the mass of each body by its acceleration (just it's velocity vector, in non-relative terms). Sum the vectors, then divide the resulting vector by 2 and apply it as a force against the objects, away from the point of impact. Remember that when applying the force F = ma applies in reverse, so you divide the force amount by the mass of the object and then just add the resulting vector to the object's existing acceleration.

Edited by Khatharr, 30 June 2013 - 02:15 PM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

### #9Waterlimon  Members

4373
Like
0Likes
Like

Posted 30 June 2013 - 02:53 PM

I have that part correct, friction should work correctly at relatively high tangential (?) velocities.

However, the problem is, that at low velocities the fricition froce will be too high which causes it to reverse the direction of the tangential velocity which causes jitter, and at high velocities, more serious unstability.

As i understand it i need to find the force that would reverse the direction of the velocity and clamp the friction impulse to that (so if the impulse is too high, itll just zero out the relative tangential velocity instead of reversing its direction)

I just need some guidance as to how to find that maximum impulse, preferrably something that also works in multiple body systems (some kind of iterative solver thingie?)

I will attempt to find the maximum impulse for a single contact (ignoring multiple simultaneous contacts)

o3o

### #10Khatharr  Members

7757
Like
0Likes
Like

Posted 30 June 2013 - 11:39 PM

The second post here may help:

http://www.gamedev.net/topic/465248-calculating-impulse-due-to-rigid-body-collision-with-friction/

Edited by Khatharr, 30 June 2013 - 11:40 PM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.