Character Movement Code not Working

Godot Version

4.3

Question

I have followed a tutorial for this code, but it doesn’t seem to work, anyone knows why?
extends CharacterBody2D
const speed = 100
func _physics_process(delta):
player_movement(delta)

func player_movement(delta):

if Input.is_action_pressed("ui_right"):
	velocity.x = speed
	velocity.y = 0
elif Input.is_action_pressed("ui_left"):
	velocity.x = -speed
	velocity.y = 0
elif Input.is_action_pressed("ui_down"):
	velocity.x = 0
	velocity.y = speed
elif Input.is_action_pressed("ui_up"):
	velocity.x = 0
	velocity.y = -speed
else:
	velocity.x = 0
	velocity.y = 0
	
move_and_slide()

Are you using the arrow keys to attempt to move and aswd?

Looks fine to me and very similar to my code…except I use movement to allow for bluetooth controllers;

	if Input.is_action_pressed("move_right"):
		velocity.x = speed
		velocity.y = 0
	elif Input.is_action_pressed("move_left"):
		velocity.x = -speed
		velocity.y = 0
1 Like

I’m using the WASD keys

1 Like