(Note: I see 14 replies were posted before I've hit Post on this, so I may be doubling up a little. Sorry, just ignore if someone beat me to bits of it)
You were printing out the joystick x values (line 20 above), what kind of numbers did you get? Minimum and maximum. The code looks like it's written for a 0 to 1 range with 0.5 (umbralJoystick) in the middle. That's because it's saying x < 0.5 is left and x > 0.5 is right. But also 0 is idle, which wouldn't fit that. Are the values being printed in the range -1 to 1 (with 0 in the middle)? Or bigger?
Looking at the joystick code, it's using a touch screen which I've never used in Godot, so not sure what that part is doing, but it looks like it's returning a position added to (24,24) then normalised, so that's probably returning positive numbers only.
Assuming it's -1 to 1 (the way a joystick would normally be used), the joystick code would need to be like this:
func getControlJoystick():
if joystick.get_value().x == 0 && joystick.get_value().y == 0:
idle()
elif joystick.get_value().x > umbralJoystick:
correrDerecha()
elif joystick.get_value().x < -umbralJoystick:
correrIzquierda()
elif joystick.get_value().y > umbralJoystick:
correrAbajo()
elif joystick.get_value().y < -umbralJoystick:
correrArriba()
This is only allowing 4 directions (like pacman) though, did you want to be able to move on diagonals? Also a joystick value that's in the deadzone (below umbralJoystick) but not zero isn't idle.
It may be better to disable the joystick check and put the keyboard check back in. Keyboard debugging is going to be easier than touch screen. Then come back to joystick once it's working.
Next, both of your up and down functions are adding to y. Adding moves down. You need the up function (correrArriba) to subtract RUN_SPEED instead.
Anyway, here's a complete working keyboard based version. I removed the animation state machine, I didn't want to have to set that up just to test. :) But up, down, left and right work with physics collisions.
extends KinematicBody2D
var player: Vector2
var RUN_SPEED = 200
const umbralJoystick = 0.5
func _ready():
pass
# warning-ignore:unused_argument
func _physics_process(delta):
player = Vector2()
getControlsKeyboard()
# warning-ignore:return_value_discarded
move_and_slide(player)
#Controlamos al personaje con el teclado
func getControlsKeyboard():
if Input.is_action_pressed("ui_right"):
correrDerecha()
elif Input.is_action_pressed("ui_left"):
correrIzquierda()
if Input.is_action_pressed("ui_down"):
correrAbajo()
elif Input.is_action_pressed("ui_up"):
correrArriba()
func idle():
pass
func correrDerecha():
player.x += RUN_SPEED
$boy.scale.x = 1
func correrIzquierda():
player.x -= RUN_SPEED
$boy.scale.x = -1
func correrAbajo():
player.y += RUN_SPEED
$boy.scale.y = 1
func correrArriba():
player.y -= RUN_SPEED
$boy.scale.y = -1
Depending on how you've set up your input mapping, you might need to change the key names. ui_left, ui_right, ui_up and ui_down are the defaults that Godot sets up for you.
Once that's working, we can come back to the joystick control.