Player model not moving in 2D forward+ project

v4.2.stable.official [46dc27791]

I am running the following script:

extends CharacterBody2D

func _physics_process(delta):
	velocity.x = 0
	velocity.y = 0

	if Input.is_key_pressed(KEY_W):
		velocity.y += 1

	if Input.is_key_pressed(KEY_S):
		velocity.y -= 1

	if Input.is_key_pressed(KEY_A):
		velocity.x -= 1

	if Input.is_key_pressed(KEY_D):
		velocity.x += 1

	velocity *= 50

There is no response from the player model when pressing any of the keys. This is what the scene looks like:


Thank you in advance for any help.

You don’t seem to be actually moving your character. Try using the velocity in the function move_and_collide(velocity).

Or alternatively move_and_slide().

1 Like

I found the issue. The script was not attached to the player node, since I had created the script from the “file → create script” menu. Thank you for your timely responses though, I should have better learned how scripts work before creating a topic.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.