move_and_slide , Keeps the player sliding on x axis.

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

Hello,

So i’m making a platform game,but i’m having troubles with the move_and_slide function.
What i can see is that the motion on the x axis isn’t going back to 0, so if i move to the left it keeps moving and adding motion to x.

Here’s my code: extends KinematicBody2D#movimiento translates to movement.const speed = - Pastebin.com

:bust_in_silhouette: Reply From: RazorSh4rk

On line 25, you probably wanted to say if not Input.is_key_pressed [...]

But an even better way would be

if LEFT_KEY:
  movement.x = -5
elif RIGHT_KEY:
  movement.x = 5
else:
  movement.x = 0

Unless you want to be able to infinitely move faster.