Player keeps sliding to the right

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

My Player keeps sliding to the right. I can move and jump just fine, but it keeps sliding to the right. It doesn’t show in the code but I did extends KinematicBody2D.

const UP = Vector2(0, -1)
var motion = Vector2()

func _physics_process(delta):
      motion.y += 10

if Input.is_action_pressed("ui_right"):
	motion.x = 100

elif Input.is_action_pressed("ui_left"):
	motion.x = -100
	motion.x = 0

if is_on_floor():
	if Input.is_action_just_pressed("ui_up"):
		motion.y = -400

move_and_slide(motion, UP)

:bust_in_silhouette: Reply From: deaton64


Seems to work OK for me.

But take a look at this: PLATFORM CHARACTER

“Note that we’re checking is_on_floor() after using move_and_slide(). The move_and_slide() function sets the value of this method, so it’s important not to check it before, or you’ll be getting the value from the previous frame.”