Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm developing a 2D platformer, although this question could probably apply to just about any 2D type physics; What is the equation for friction? I have sort of a hacky type of friction set up in my game currently, but I'm not satisfied with it because it doesn't account for all forces being applied to my character outside of whatever forces he's generating himself.

share|improve this question
7  
speed *= 0.99; –  Markus von Broady Sep 28 '12 at 21:45
    
This will never actually bring speed back down (or up) to 0 though? –  TheBroodian Sep 28 '12 at 21:58
2  
if ( speed < 0.01 ) speed = 0; –  Markus von Broady Sep 28 '12 at 21:59
2  
Remember Coulomb's Law of Friction: Kinetic friction is independent of the sliding velocity. So applying friction by using the speed probably isn't the best way to do it. –  Byte56 Sep 28 '12 at 22:01
1  
@Gajoo Of course that's true. I'm sure a lot of games do it that way. I just wanted to make sure that it was know that it wouldn't be physically accurate and may have some weird results for things that have a wide range of velocities. I would also recommend Markus make it an alternative answer, as it's a good one. –  Byte56 Sep 28 '12 at 22:10
show 3 more comments

1 Answer

up vote 11 down vote accepted

There's two types of friction, static friction and kinetic friction. Static friction is the friction that needs to be overcome to get something moving from rest. You'll notice when pushing a box across the floor, it can often take more force to get it moving than to keep it moving. Or you'll be applying force and it will jolt forward and you'll have to not push as hard. That jolt forward is the point when static friction is overcome and you're dealing with kinetic friction. Kinetic friction is almost always (always?) less then static friction.

Either way, friction is a force just like acceleration. It's calculated based on the normal force of the objects and coefficent of friction (µ).

enter image description here

This free body diagram shows a few forces.

  • Green: The force of friction.
  • Purple: The force being applied to move the object
  • Blue: Gravity
  • Red: The normal force, will equal gravity if the object is not sinking into the surface below.

So when the force of friction and the force being applied are equal, the object will not accelerate. So if it's stopped, it's not going anywhere and if it's moving it'll continue to move at that speed.

So you're going to want to collect some information to simulate friction.

  • The types of materials, this is needed to get the coefficent of friction (µ).
  • The normal force

Then you can simply calculate the force of friction with the following:

friction = µ • normalForce

When you're summing up your forces you include this force. If you have no other accelerations, then your friction is going to be the only force, and will slow your object down.

share|improve this answer
    
@MarkusvonBroady you sure it was two minutes? cause the question was asked 30 mins ago! –  Ali.S Sep 28 '12 at 22:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.