Touch moviment in godot

285 Views Asked by At

I'm not able with any youtube tutorial and blogs to make a joystick movement for my topdown 2d game on godot

as I said, follow step by step several tutorials on the internet / youtube and I couldn't get my joystick for my topdown2d game

1

There are 1 best solutions below

0
Theraot On

You should not need any special code to use a joystick with Godot. Run of the mill code like this should work:

extends KinematicBody2D

var speed := 500.0

func _physics_process(_delta:float) -> void:
    var velocity := Vector2(
        Input.get_axis("left", "right"),
        Input.get_axis("forward", "backward")
    ) * speed
    move_and_slide(velocity)

Either that or something similar you might find in most tutorials. Which probably use "ui_left", "ui_right", "ui_up" and "ui_down" which are pre-defined actions. And yes, there are also pre-defined joystick inputs for those actions, but they might not be correct for your device.


Before configuring the actions, make sure the device is recognized by the operating system (you might need to install/update drivers). You might also want to run a diagnostic tool to check if it can send input.

Now, configure the actions on Project Settings -> Input Map. You can add new actions or modify the pre-existing ones. Once you have the action defined, click on the "+" icon on the right, and there you will find the "Joy Button" and "Joy Axis" options which will let you configure the joystick input for the action. Double click will allow you to modify the existing ones.

There is always the chance you configured the wrong input on the wrong action. You could figure it out by trial an error or with the help of a diagnostic tool.

If your device works, the configuration is correct and it still does not work. We could be talking of a compatibility issue. You might want to report a bug on github.

I can't help you further without knowing what did you try and the results you got.