Friction

Hey there, got a simple question, I have acceleration working using the panda physics, but I’m not sure how to add friction, at the moment the force gets applied to the object, and the object just keeps going and going, what I need is once the forward key is no longer held down, the object comes to a halt.

Thanks for any help :slight_smile:

Mystery

One of the simplest ways to apply friction in almost any physics system is to simply take the current velocity and apply an acceleration in the opposite direction as the velocity by negating the velocity vector and then scaling it by some fixed value (essentially a friction coefficient). This acceleration should be applied at all times for realistic behavior, possibly with exceptions such as if a character jumps off of the ground into the air, where air friction would be less than ground friction, and maybe small enough that it can be ignored.

Sometimes to bring an object to a full stop it helps to simply set the velocity of the object to zero once it drops below some very small amount, otherwise the friction acceleration can possibly cause a bit of an oscillation effect. Just make sure to only apply this test whn other forces aren’t acting to accelerate the object.

You might also want to try out PhysicsManager.setViscosity(), though the documentation isn’t clear enough to say whether this will do what you want I’m guessing it might provide a sort of global friction.

Thanks :smiley:

Mystery