2D body not moving

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

I wrote some code of basic movements for a 2D kinematic body. I did that and its not moving and stuck at the top of the debug screen.

    extends KinematicBody2D

var movespeed = 500

func _ready():
	pass # Replace with function body.
func _physics_process(delta):
	var motion = Vector2()

	if Input.is_action_pressed("up"):
		motion.y -= 1
		if Input.is_action_pressed("down"):
			motion.y += 1
	if Input.is_action_pressed("left"):
		motion.x += 1
	if Input.is_action_pressed("right"):
		motion.x -= 1
		
	motion = motion.normalized()
	motion = move_and_slide(motion * movespeed)

Does anybody know where I went wrong?

:bust_in_silhouette: Reply From: Mxt08

I don’t see an error in the code, but the problem can be that there is a conflict between the Input.is_action_pressed and the input map.

Wdym by conflict? like there’s a error? there’s no error appearing on my screen at least

Miguelxi | 2021-03-21 20:49

:bust_in_silhouette: Reply From: Magso

You’re checking if up and down are being pressed at the same time due to the indentation, bring the ‘down’ if statement to the left. Also it’s not necessary to have motion = move_and_slide here.

Oh ok thanks so much

Miguelxi | 2021-03-21 22:08

tried it out and it didnt work

Miguelxi | 2021-03-23 19:02

Just checking, is “down” in your input map? The default is “ui_down”.

Magso | 2021-03-23 21:38