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()