# How to implement friction in a physics engine based on “Advanced Character Physics”

I have implemented a physics engine based on the concepts in the classic text Advanced Character Physics by Thomas Jakobsen. Friction is only discussed very briefly in the article and Jakobsen himself notes how "other and better friction models than this could and should be implemented."

Generally how could one implement a believable friction model on top of the concepts from the mentioned article? And how could the found friction be translated into rotation on a circle?

I do not want this question to be about my specific implementation but about how to combine Jakobsens ideas with a great friction system more generally. But here is a live demo showing the current state of my engine which does not handle friction in any way: http://jsfiddle.net/Z7ECB/embedded/result/

Below is a picture showing and example on how collision detection could work in an engine based in the paper. In the Verlet integration the current and previous position is always stored. Based on these a new position is calculated. In every frame I calculate the distance between the circles and the lines. If this distance is less than a circles radius a collision has occurred and the circle is projected perpendicular out of the offending line according to the size of the overlap (offset on the picture).

Velocity is implicit due to Verlet integration so changing position also changes the velocity. What I need to do know is to somehow determine the amount of friction on the circle and move it backwards parallel to the line in order to reduce its speed. • Very nice article! What's your friction like right now? – Mikael Högström Aug 25 '12 at 0:22
• Yes. It's a great article. It's very simple but yet I've got an entire engine suitable for my purpose working based on it. Except friction ;) – paldepind Aug 25 '12 at 10:18
• And nice video too. Looks promising! – Mikael Högström Aug 25 '12 at 18:25

You should take a look at Mathias Mueller et all's "position based dynamics" paper. It's basically the same as Jacobsons' paper and he might give you more info about friction.

http://www.matthiasmueller.info/publications/posBasedDyn.pdf

They state that friction is basically damping the particle's velocity in the plane of the collision by some scalar value.

Note that this doesn't give you any coulomb friction effects (the amount of momentum into the collision doesn't affect the magnitude of the friction force) but you might be able to get that by considering the particle's velocity into the collision plane.

• What if, when applying an impulse to an otherwise stationary body, you check for a certain threshold. If the impulse's component on the contact surface is lower than that threshold, you could set it to zero to immitate the effects of static friction. From then on, dynamic friction is exactly how you described it. +1 – teodron Nov 16 '12 at 13:09

In a "normal" rigid body engine you would model friction as impulses perpendicular to the normal. I would guess that in this context that would mean instead of impulses set the position of the affected particle appropriately. With the constraints in place this should, if I understand the article correctly, then iteratively reach a state where friction has also affected rotation. I am guessing that by "better model" the author means better way of determining the amount of friction than a linear projection of interpenetration. This is however a guess on my side as I have never implemented physics by this approach myself.

EDIT:

To calculate the size of friction forces you have the offset-value in your image. As you're using verlet with fixed timestep we know that this offset is actually the velocity that the contact had in the direction of the contact normal (well not exactly, and I think this is what the author means by making a better approximation of friction). Knowing the velocity along the contact normal is essential as we can use it to determine the impulse. The best way is to apply friction in the form of impulses in each frame where there is a contact. The size of the friction in the axes parallell to the plane of contact is determined by the friction coefficient (determined by the materials, for example 0.7 for rather high friction). The maximum friction you could have is the friction coefficient multiplied by the offset. Do note that this value could be bigger than the actual velocity along one of the axes. In that case you have static friction and the particle should not move at all in that axis. If the value is less than that the particle will move a little bit but be slowed down, ie dynamic friction.

• You are correct. The tricky part, for me at least, is to determine how to "set the position of the affected particle appropriately". – paldepind Aug 25 '12 at 9:52
• Ahh ok, then I see where you're at. I have an idea for a solution, I'll edit the answer – Mikael Högström Aug 25 '12 at 18:03
• That's exactly the technique described in the paper ;) . I think I'll try an implement it and se if it's good enough for my project though. – paldepind Aug 26 '12 at 16:56
• Ahh I guess so... Seems like the method is almost the same as for a rigid body engine just take into account the verlet integration and apply impulses as position changes instead. – Mikael Högström Aug 26 '12 at 17:08