Friday, November 29, 2019

xna - Friction in 2D game


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.



Answer



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.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...