How to change arrow controls to AWSD controls?

Godot Version

4.2.2

Question

I created control script fro my game character. But “ui_” tips have “up/down/right/left” variants only. What to do? Please help.

extends CharacterBody2D


const SPEED = 300.0

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")


func _physics_process(delta):
	
	var direction_y = Input.get_axis("ui_up", "ui_down")
	if direction_y:
		velocity.y = direction_y * SPEED
	else:
		velocity.y = move_toward(velocity.y, 0, SPEED)

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var direction_x = Input.get_axis("ui_left", "ui_right")
	if direction_x:
		velocity.x = direction_x * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)

	move_and_slide()

Create your own input actions for controlling, such as “move_left”, “move_right”, and “jump”. The default generated code of CharacterBody2D did tell you right? Open the project settings (which is under the “Project” tab), and head over to the “Input Map” tab beside the “General” tab, the UI is pretty straightforward to use.

2 Likes

Here is some input tutorials in the documentation, with pictures of what coderjo mentioned: Input examples — Godot Engine (stable) documentation in English

3 Likes