[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Friction help



On Tue, Jan 13, 2009 at 5:49 PM, <kiliansto@xxxxxxxxx> wrote:
After I move, the box slows down appropriately, but then the speed
passes 0 and the box shoots off the other way. The equation (in real
life) is mS (Coefficient of static friction)*Normal Force >= friction
force. So lets say I am slowing down at a rate of -2m/s^2, if I hit 1,
the next number will be -1 and I shoot off in the other direction. How
do I fix this an still have backwards movement?


In real life, friction is only a force that opposes the relative motion between 2 objects, so you'd simulate this by never applying enough of the force to change the sign of the relative velocity.

Meaning if the velocity is 1m/s, and you integrate your friction and get -2m/s, then only apply -1m/s worth. Usually this is done with a line like this:
if abs(friction_delta) > abs(relative_velocity):
 relative_velovity