Why does this happen?

Godot v4.3

I’m too new to godot. I made this code and I don’t know why I get an error on the last line. Does anyone know why it happens?

var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
input_vector.y = Input.get_action_strength(“ui_down”) - Input.get_action_strength(“ui_up”)
input_vector = input_vector.normalized() * SPEED

move_and_slide()

move_and_slide is based on the velocity value. Ensure that it is set properly.

1 Like

What is the error? if the last line is only move_and_slide() then I presume you have not extended a physics-based class like CharacterBody2D, what does the first line of your script say, what are you trying to program?

Also a much better way to do this input is uing Input.get_vector, results in normalized inputs in just one line.

var input_vector := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
1 Like