Character doesn't move

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

So, I’m new using this engine and watched a tutorial to make a simple platformer, but when I use motion.x = MAX_SPEED it doesn’t move, I checked if I introduced something wrong in the code or keymaps and everything seems fine.

    var left = Input.is_action_pressed("left")
var right = Input.is_action_pressed("right")
var MAX_SPEED = 20
var motion = Vector2()

if left:
	motion.x = -MAX_SPEED
elif right:
	motion.x = MAX_SPEED
else:
	motion.x = 0

I’ll appreciate any help, thx.

Try putting ui_left and ui_right instead of left and right. Also, since you didn’t post the entire code, are you using motion to update the position of the character?

exuin | 2020-09-06 21:44

:bust_in_silhouette: Reply From: kidscancode

There’s nothing in this code that shows any kind of movement at all. All you’ve done is change the value of a variable called motion. To move something, you have to change its coordinates, which for 2D nodes, is represented by position.

If this is a kinematic body, then you’ll need to use the body’s provided movement methods - either move_and_collide() or move_and_slide()- to move the body and detect collisions.

See this tutorial for details on how to use KinematicBody2D: