Why is the character isn't moving at all when I pressed W, A, S, D?

extends CharacterBody3D

var speed = 5.0
var gravity = -9.8

func _physics_process(delta):
var input_dir = Vector3.ZERO

if Input.is_action_pressed("ui_up"):
	input_dir.z -= 1
	print("W pressed")
if Input.is_action_pressed("ui_down"):
	input_dir.z += 1
	print("S pressed")
if Input.is_action_pressed("ui_left"):
	input_dir.x -= 1
	print("A pressed")
if Input.is_action_pressed("ui_right"):
	input_dir.x += 1
	print("D pressed")

input_dir = input_dir.normalized()
velocity.x = input_dir.x * speed
velocity.z = input_dir.z * speed

if not is_on_floor():
	velocity.y += gravity * delta
else:
	velocity.y = 0

move_and_slide()

Is your script attached to the Player?
Is anything printed in the console when you press these keys?

2 Likes

Have you changed the default settings for input mapping? the built-in “ui_[direction]” inputs default to arrow keys, not WASD. For WASD movement you need to set up the inputs maually by going to project > project settings > Input Map. There you can either use “add new action” to make your own inputs, or edit the default options.

2 Likes

It turned out I named wrong function that isn’t connected to Input Map.