"Slippery" movement in top/down game?

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

Hi there. I’m currently working on a top/down game and wanted to make movement slippery whenever you are on ice or the like. This is how movement is controlled right now.
What would need to be changed or added into this so I can make slippery movement?

var motion = Vector2()	

motion.x = int(Input.is_action_pressed("d")) - int(Input.is_action_pressed("a"))
motion.y = int(Input.is_action_pressed("s")) - int(Input.is_action_pressed("w"))
motion = motion.normalized()
motion = move_and_slide(motion * ms)
:bust_in_silhouette: Reply From: Scavex

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 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 = motion.linear_interpolate(Vector2.ZERO, 0.05)

	motion = move_and_slide(motion)