Followed a smooth movement tutorial, but player can't move [BEGINNER]

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

So, I was following this tutorial by HeartBeast and I copy pasted the code by hand, the only different things are the variable names. For some reason, it doesn’t work… this is the code

extends KinematicBody2D

var limit_speed: float = 500
var acceleration: float = 2000
var motion = Vector2.ZERO

func _physics_process(delta):
	var axis = get_input_axis()
	if axis == Vector2.ZERO:
		apply_friction(acceleration * delta)
		apply_movement(axis * acceleration * delta)
	motion = move_and_slide(motion)

func get_input_axis():
	var axis = Vector2.ZERO
	axis.x = int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left"))
	axis.y = int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up"))
	return axis.normalized()
func apply_friction(amount):
	if motion.length() > amount:
		motion -= motion.normalized() * amount
		motion = Vector2.ZERO

func apply_movement(acceleration):
	motion += acceleration
	motion = motion.clamped(limit_speed)

Just by writing that down, I guess it was supposed to move when I pressed WASD or the direction keys, but nothing happens, any idea why? How is it supposed to know that I’m pressing WASD if I never coded the controls? I guess I didn’t understand a part of the video xD

screenshot of the code: Screenshot by Lightshot sorry for not knowing how to use ctrl + k :d

Edited to fix your formatting. Please format code samples.

kidscancode | 2020-05-02 23:25

you need to setup the INPUT KEY in your project settings.
Go to project>Setting>Input
And then addd one input per key matching the name that was given to you in the script.
Good luck !

quizzcode | 2020-05-06 20:46

:bust_in_silhouette: Reply From: Asthmar

Did you put in your input keys in the the project settings?

If not, you do it by going to project → project settings → Input map

From there you must input in your keys. In your case just add “a” to “ui _ left” , ‘w’ to “ui_up” and so on. Also you add keys by pressing the plus sign that is across from the action name.

I tried the code and it works when using the directional keys , but to use WASD you are going to have to add them as shown above. Hope that works!

Thank you Asthmar! I’ll be sure to check it out later. Sorry for answering like 15 days later, didn’t receive the notification e-mail ^^’

Is it wrong to thank people for the answers, like, is it bothering to receive thank you responses? Sorry if that’s the case :d

Rawayju | 2020-05-18 20:13