func _physics_process(delta):
var playerInput = get_input()
velocity = playerInput * SPEED
move_and_slide()
Question
i’m very new to coding and tried without a tutorial for the first time, but i’m so stuck. My inputs all match up from my input map but my character still wont move. please help!!
func get_input() → Vector2:
var input = Vector2.ZERO
# Changed to get_axis for smoother input handling
input.x = Input.get_axis(“left”, “right”)
input.y = Input.get_axis(“up”, “down”)
return input.normalized()
func _physics_process(delta: float) → void:
# Get the input direction
var direction = get_input()
# If there's input, move in that direction
if direction != Vector2.ZERO:
velocity = direction * SPEED
else:
# Optional: Add friction when no input is detected
velocity = velocity.move_toward(Vector2.ZERO, SPEED * delta)
# Apply the movement
move_and_slide()
I’m a beginner coder but can’t see anything wrong. Can you post all the code in a preformatted text block so we can see it?
(I’ve cut and paste a CharacterBody3D script template below)
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
Godot editor complained about these “ you used as invalid character, are you sure editor is not showing any errors? Replacing the “ in code the character moved but the inputs are inversed
Are you totally sure your inputs names are correct? Try replacing them by "ui_up", "ui_down", "ui_left" and "ui_right" and use the arrows to move the character.
Also your code can be simplified to this (if your input map is correct or use the ui_ versions):