Below I am attaching a code that gives the player a slippery movement. The desired effect here is due to the linear_interpolate()
method. You can further search the Godot Docs to know about this method for better clarification but what it does is, it makes sure that the motion
won't become 0 suddenly. The value of motion will decrease by 0.05 and this stops the player slowly once you stop pressing the input key.
var ACCELERATION = 800
var MAX_SPEED = 500
var motion = Vector2()
func _physics_process(delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
if input_vector != Vector2.ZERO:
motion += input_vector * ACCELERATION
motion = motion.clamped(MAX_SPEED)
motion.normalized()
else:
motion = motion.linear_interpolate(Vector2.ZERO, 0.05)
motion = move_and_slide(motion)