How to implement friction on a kinematic body?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By xofox

I have a kinematic body that the player controls but I can’t figure out how to slow the speed of it over time. I have tried putting a static body underneath it in order to have a friction value but it doesn’t seem to affect the kinematicbody. any tips?

:bust_in_silhouette: Reply From: kidscancode

The easiest way to do this is with lerp(). For example:

velocity.x = lerp(velocity.x, 0, friction)

Where friction is some value between 0 and 1. This will cause the player’s horizontal speed to gradually ramp down to 0 from its current value.

You can see this in practice with a full explanation here:
http://kidscancode.org/godot_recipes/physics/kinematic_friction/